: I'm sorry, I might sound lame, but these buffering and autoflush problems seem a 
:bit(?) theoretical and far-fetched to me. Would you please show me examples of 
:situations (or links to codes) where the use of autoflush instead of buffering IO (or 
:vice versa) would be crucial. 

One area is where you're mixing up prints to STDOUT and STDERR. STDERR
is not buffered, but STDOUT is, so while whatever you print to STDERR
will go directly out the door, the stuff printed to STDOUT will hang
around until the buffer is full. This is really annoying when you're
debugging: warn()s and print STDOUTs will be out of synch.

Another place is CGI. Without buffering, print()s to STDOUT go straight
back to the browser.  Otherwise, the browser will not show anything
until everything is printed. If you have access to a CGI area, try the
following code:

#!/usr/bin/perl
$|++;
print STDOUT "Content-type: text/html\n\n";
print STDOUT "Before sleep...<p>";
sleep 3;
print STDOUT "...after sleep.";

With the $|++, the "Before sleep..." line will appear on your browser,
then it will sit for three seconds, then "...after sleep." will appear.

With $|++ commented out, the browser will sit for 3 seconds, and then
all the stuff will appear.

Sometimes it's helpful in long CGI scripts to have something appear
immediately, to keep the user interested.

-- tdk

Reply via email to