There are three buffering states:
- unbuffered
- block buffered: Writes when 4KB* is accumulated.
- line buffered: Writes when \n is encountered or 4KB* is accumulated.
If a handle is buffered, line buffering is always and only used when the file handle is connected to a terminal.
So, if you're writing to a file, \n won't flush. But if you're writing to STDOUT and it hasn't been redirected, \n will flush if buffering wasn't turned off.
You can turn on buffering using
use IO::Handle qw( );
FH->autoflush(0);
You can turn off buffering using
use IO::Handle qw( );
FH->autoflush(1);
You can flush manually using
use IO::Handle qw( );
FH->flush();
* — Well, I *think* the buffer size is 4KB.
|