Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: perl loop counter

by friedo (Prior)
on Jul 18, 2008 at 15:56 UTC ( #698656=note: print w/ replies, xml ) Need Help??


in reply to Re: perl loop counter
in thread perl loop counter

Only if you're printing to a file. If STDOUT is connected to a terminal (as it is most of the time) it won't be buffered.

Update: I must be drinking the stupid juice today. Ttys are line-buffered, duh.


Comment on Re^2: perl loop counter
Replies are listed 'Best First'.
Re^3: perl loop counter
by almut (Canon) on Jul 18, 2008 at 16:20 UTC
    ...it won't be buffered

    Actually, STDOUT is line buffered by default when connected to a tty, i.e. - as zentara said - output will be written either upon encountering a newline, or when the buffer has filled up (or when the program terminates, and the buffer gets flushed).

    Try playing with something like

    for (1..3000){ print "$_ "; sleep 5 unless $_ % 1000; }
Re^3: perl loop counter
by zentara (Archbishop) on Jul 18, 2008 at 16:22 UTC
    Are you sure? On my linux xterm, this prints out in roughly 2k chunks.
    #!/usr/bin/perl for (1..6000){ print $_; select (undef,undef,undef,.001); #small delay to see buffering effects }

    I'm not really a human, but I play one on earth CandyGram for Mongo
      try
      for (1..6000){ print "$_ " ; print "\n" if /00$/; select (undef,undef,undef,.0001); }
      and you'll see that when you give it a newline, it flushes.
      []s, HTH, Massa

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2015-07-08 08:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (96 votes), past polls