-----Original Message----- From: Harold Castro [mailto:[EMAIL PROTECTED] Sent: Mon 2/21/2005 9:42 AM To: [email protected] Cc: Subject: Perl waits for while to finish before printing if on the same line,why?(countdown prog) Hi, I'm new to perl and i'm trying to create a simple program that will act like a time bomb but will print a dot(something like a progress bar every second until the specified time arrives. Here's my code. my $countdown = 5; while ($countdown > 0){ print "\."; 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? I told it to print a single dot every 1 second. Do you know another way of making my progress bar program that display a single dot every one second on the same line until it reaches a given time? Thank you! __________________________________ Do you Yahoo!? Yahoo! Mail - You care about security. So do we. http://promotions.yahoo.com/new_mail -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response> Hi Harold, if you set $| to some postive value, it will work. add one line to your script. --------------------------------- $| = 1; my $countdown = 5; while ($countdown > 0){ print "\."; sleep 1; $countdown--; } print "Kaboom!!" --------------------------------- The problem is with buffers. Though I am not very clear whats happening internally, I can say setting $| to some positive value will at the beginning of script will solve the problem. It flushes the buffer after every print. HTH Tapas -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
