Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: The While Loop is Breaking My Variables

by pg (Canon)
on Nov 22, 2005 at 03:58 UTC ( [id://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); }

Or:

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-03-28 19:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found