On 02/22/04 05:09, daniel wrote:
Hi helpers,

I'm very new in perl programming(in programming at all acutally) and
wondering about the following piece of code which I was running under
W2K command-line:

print "First";
sleep 2;
print "Second";

I thought the script would print First then wait for 2 seconds and than print Second. But the script ist waiting 2 seconds first and than it print FirstSecond ????

By default, output to the console is buffered for efficiency. Since output to the console is relatively expensive in terms of time the system libraries will save up a couple of output operations and ouput it at once. Most of the time this is what you want, but occasionally it gets in the way. The perl idiom for turning of the output buffering to the console is:


$| = 1;

(You can look up the special variable $| in the perlvar manpage.)

Put the above line at the top of your script and output will be unbuffered, i.e. it will appear as soon as the print function is completed.

Regards,
Randy.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to