How to implement "sleep" in Perl ?

I tried,

#!/usr/bin/perl
print "check 1";
print "check 2";
sleep(5);

The above works fine but sleep takes the higest priority. Looks weird

In above program "sleep" executes first and then "print" comes next. I would like the program to be executed in "sequence" , Print at first and then sleep ( Well that is how it should be :wall:)

Thanks in advance

#!/usr/bin/perl
print "check 1";
print "check 2\n";
sleep 5;
1 Like

Hi Bala,

It worked. I wander, \n is for new line. How does that make difference in the program ? .

If I have to implement many sleep function in a very huge program/script, do I have to add "\n" for print statement befor every sleep function. Well, what should I do if there is no print statement before sleep.

Thanks,

#!/usr/bin/perl
$|++; #set STDOUT unbuffered; use with caution
print "check 1";
print "check 2";
sleep 5;
1 Like