Re: Why doesn't this work?



HerbF@xxxxxxxxxxxxx wrote:
Glenn Jackman wrote:
At 2009-08-20 02:08PM, "HerbF@xxxxxxxxxxxxx" wrote:
I'm trying to write a simple routine to print a character every second. I
have:

foreach (1..5) {
print "*";
sleep 1;
}

When I run it, it waits for the full 5 seconds to tick by, and then prints
the string '*****'. Why doesn't it print an asterisk every second until
finished?

Your output is buffered. Set $|=1 first.

Tried that, but it made no difference.

Then something else is buffering on top of Perl's buffering. See
'perldoc -q buffer' for some in-depth discussion and for other ways to
work around buffering.

jue
.



Relevant Pages

  • Re: parsing Makefiles
    ... > is looping BASED ON THE OUTPUT of the make command. ... > you will find that NOTHING arrives in the 'foreach' loop until the ... > Hence, if you want to print output as the MAKE COMMAND OUTPUT arrives, ... is Perl buffering the output ...
    (perl.beginners)
  • Re: weird behavior w/ puts -nonewline
    ... Sample code is below. ... Seems like it is buffering the puts until the entire ... >foreach is run. ...
    (comp.lang.tcl)