Namudril has asked for the wisdom of the Perl Monks concerning the following question:

greetings, monks! i need to make delays in program flow
using sleep $timeout; or select undef, undef, undef, $timeout; leads to the unexpected result:
print "hello,\n"; sleep 2; print "world!\n"; sleep 2; print "bye!";
the result is:
#hello, - instantly #after 4 seconds delay: #world! #bye!
really i need a "beeper" with delays:
#some kind of cycle: {print "\a"; sleep $timeout; }

Replies are listed 'Best First'.
Re: making delays
by gloryhack (Deacon) on Dec 17, 2006 at 08:17 UTC
    Try unbuffering STDOUT:
    #!/usr/bin/perl use strict; use warnings; $| = 1; # This is the critter you want print "hello,\n"; sleep 2; print "world!\n"; sleep 2; print "bye!\n";
Re: making delays
by virtualsue (Vicar) on Dec 17, 2006 at 10:57 UTC