Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: The While Loop is Breaking My Variables

by pg (Canon)
on Nov 22, 2005 at 03:58 UTC ( #510626=note: print w/replies, xml ) Need Help??

in reply to The While Loop is Breaking My Variables

Your output will not be flushed until the program is finished, unless you forced it to be flushed in a way I demoed at the end of this post, or if your output is big enough to trigger the flush. Try the following code and observe, you will see that the output does not come out on the screen after 1 second, and the first batch of print only comes after about 20 seconds. That is the effect of buffering.

while (1) { print "0123456789" x 20; sleep(1); }

With manual input, most likely you don't have enough input to trigger the print out. The flushing can also be triggered by the end of the program, but with a dead loop that's not happening either.

Even if there is any output, it will be quickly flushed out of the physical screen by all the error messages, and you are probably still not going to see the output.

But with this code you will see something printed every second:

while (1) { print "0123456789" x 20 . "\n"; sleep(1); }

This too:

$| ++; while (1) { print "0123456789" x 20; sleep(1); }


use IO::Handle; STDOUT->autoflush(); while (1) { print "0123456789" x 20; sleep(1); }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://510626]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2020-10-29 02:57 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (267 votes). Check out past polls.