Charles K. Clarkson wrote:

Harold Castro <[EMAIL PROTECTED]> wrote:

: my $countdown = 5;
: while ($countdown > 0){
: print "\.";

   No need to escape the period in a double quoted string.


: sleep 1;
: $countdown--;
: }
: print "Kaboom!!"
: : And the result..
: after waiting for 5 seconds, it displayed this line at once:
: : .....Kaboom!!
: : : Why does this happens with a while loop?


By default, perl buffers output. Nothing is printed until
the buffer fills or the script ends.


I/O lib buffers output also by line (for example, try <print ".\n";> and you'll see the dot before the script ends or buffer fills)

You can change this
behavior by setting $| to 1.

$| = 1;

my $count_down = 5;
while ( $count_down-- ) {
   print '.';
   sleep 1;
}
print "Kaboom!!"


HTH,

Charles K. Clarkson




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to