On 3/1/07, David Moreno Garza <[EMAIL PROTECTED]> wrote:
What's the proper way to handle buffering? I mean, to prevent it.
Sometimes you just want to output immediately; however as Tom mentioned 'cat' doesn't output until the buffer is closed; for example - $|++; # Setting this has no effect on 'cat' open(o,"|cat"); print o "Not first because of buffering.\n"; # close(o); # Uncomment this line for 'cat' to become closed 1st... print o 0 x 99999; # Does cat get printed now? Buffer became full. #sleep 1; # Yes, buffer is full; LINE 2 gets printed in the middle. # But probably not a good thing ... LINE 2 appears out of context ... $_ = "LINE 2: gets printed first?\n\n"; print; sleep 1; __END__ cat: Buffer gets closed here because all open buffers are closed when the program finishes... Note: In the 'buffer full' example, use - perl oo.pl | less Be careful to watch for the output of LINE 2; with 100k characters you might miss LINE 2 - it gets printed immediately after the 'buffer flush' and before the 'end of the data stream' ... The bottom-line? Be careful of your I/O -- things that seem to make program (logical) order sense may not produce expected results... One possible answer to your question - # A long winded approach might use # (modified from FAQ 8) - use IPC::Open3; $_ = "I am the Alpha and the Omega (UT99 Player Xan)\n"; open(o, "cat $_"); print; print "Hmmmm?\n"; -- WC (Bill) Jones -- http://youve-reached-the.endoftheinternet.org/ http://pgp.mit.edu:11371/pks/lookup?op=vindex&search=0x2A46CF06&fingerprint=on -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/