How to control timing of buffer flushing in Perl
How does exert more control on buffering in Perl? I know that I can use autoflush to flush the buffer immediately, or I can do nothing and let Perl flush when it feels like it.
But can I change the buffer size? Or can I force a flush every, say, 30 seconds?
I'd like to know how to do this for either a file handle or STDOUT. I've tried going through the IO::Handle documentation, but haven't been able to figure out what I need.
But can I change the buffer size?
Before 5.14, the size of every file handle's buffer was 4096 bytes.
Since 5.14, the size of every file handle's buffer can be chosen when Perl is built (by passing -Accflags=-DPERLIOBUF_DEFAULT_BUFSIZ=num_bytes to Configure). The default is 8192 bytes.
Or can I force a flush every, say, 30 seconds?
You can force a flush whenever you want to.
use IO::Handle qw( ); # Not needed in 5.14+ $fh->flush(); STDOUT->flush();