For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > February 2005 > Perl waits for while to finish before printing if on the same line, why?(countdown pr









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Perl waits for while to finish before printing if on the same line, why?(countdown pr
Mark Jayson Alvarez

2005-02-21, 3:57 am

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 - 250MB free storage. Do more. Manage less.
http://info.mail.yahoo.com/mail_250
Gavin Henry

2005-02-21, 8:56 am

On Monday 21 Feb 2005 04:08, Mark Jayson Alvarez wrote:
> 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?


See:

http://search.cpan.org/~fluffy/Term.../ProgressBar.pm

>
> Thank you!
>
>
>
>
>
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail - 250MB free storage. Do more. Manage less.
> http://info.mail.yahoo.com/mail_250


--
Just getting into the best language ever...
Fancy a yourname@perl.me.uk or something
on http://www.perl.me.uk Just ask!!!
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com