When printing to a filehandle, output doesn’t appear
immediately. This is a problem in CGI scripts running on some
programmer-hostile web servers where, if the web server sees warnings
from Perl before it sees the (buffered) output of your script, it
sends the browser an uninformative
Error. These buffering
problems arise with concurrent access to files by multiple programs
and when talking with devices or sockets.
Disable buffering by setting the per-filehandle variable
$| to a true value, customarily
$old_fh = select(OUTPUT_HANDLE); $| = 1; select($old_fh);
Or, if you don’t mind the expense, disable it by calling the
autoflush method from the IO modules:
use IO::Handle; OUTPUT_HANDLE->autoflush(1);
In most stdio implementations, buffering varies with the type of output device. Disk files are block buffered, often with a buffer size of more than 2K. Pipes and sockets are often buffered with a buffer size between ½ and 2K. Serial devices, including terminals, modems, mice, and joysticks, are normally line-buffered; stdio sends the entire line out only when it gets the newline.