Re: Print question
From: Sherm Pendley (spamtrap_at_dot-app.org)
Date: 01/12/05
- Next message: A. Sinan Unur: "Re: cgi-bin script not printing output on html"
- Previous message: Jim Keenan: "Re: CPAN troubles again"
- In reply to: jl_post_at_hotmail.com: "Re: Print question"
- Next in thread: jl_post_at_hotmail.com: "Re: Print question"
- Reply: jl_post_at_hotmail.com: "Re: Print question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 11 Jan 2005 21:38:10 -0500
jl_post@hotmail.com wrote:
> Normally, a print() statement in Perl won't print a newline
> unless you tell it to.
Quite correct, but that doesn't answer the question. The OP is asking how to
unbuffer output, so it appears immediately, rather than a line at a time.
To illustrate this, insert a sleep(2) between each of the prints in your
example:
> #!/usr/bin/perl
> use strict;
> use warnings;
> print "H";
sleep(2);
> print "i";
sleep(2);
> print "!";
sleep(2);
> print "\n";
> __END__
You'd think this would print one letter at a time, with a pause in between -
but that's not what happens. What usually happens is a six second pause,
and then "Hi!" printed all at once, because output is buffered. (I say
"usually" because it's an OS feature, not a Perl feature, so it may not
apply to everyone. In particular, I don't know if it's true on Windows.)
The FAQ I mentioned addresses the buffering question. In brief - the FAQ
gives much more detail - you set $| to a true value to disable buffering.
So if you add:
$| == 1;
To your example, you get what the OP presumably wants from the sleep(2)
calls above - a two-second pause between each letter.
sherm--
-- Cocoa programming in Perl: http://camelbones.sourceforge.net Hire me! My resume: http://www.dot-app.org
- Next message: A. Sinan Unur: "Re: cgi-bin script not printing output on html"
- Previous message: Jim Keenan: "Re: CPAN troubles again"
- In reply to: jl_post_at_hotmail.com: "Re: Print question"
- Next in thread: jl_post_at_hotmail.com: "Re: Print question"
- Reply: jl_post_at_hotmail.com: "Re: Print question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|