in reply to sleep problem !
A number of people have pointed to the correct answer: auto-flush is off. No one has (yet) explained why that matters.
With auto-flush off, your print statements will send output to the buffer; the buffer will write to the screen when it feels it is most efficient to do so (vast simplification). When you turn auto-flush on, the buffer flushes after every print, causing output to display immediately.
It is generally good practice to localize these type of variables, as not doing so can cause unexpected behavior in modules you may use.
{ local $| = 1; ## turn on auto-flush locally print 'processing'; for (1..5) { print '.'; sleep 1; } }
As long as I'm spouting about best practices, note my use of single quotes for strings. Generally speaking, you should use double quotes only when you need to interpolate the string (for example, print "value: $val\n";). It reduces bugs, and there's even a tiny performance benefit. Also note the for loop style I've used: C-style loops can often be avoided (and their potential for bugs along with them).
And, marto is absolutely correct: if a progress bar is what you're after, you should definitely look into modules written for that purpose. On the terminal, my favorite is Term::ProgressBar.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: sleep problem !
by prad_intel (Monk) on Sep 23, 2005 at 04:13 UTC | |
by Skeeve (Parson) on Sep 23, 2005 at 11:25 UTC |