perlbufferautoflush

Why aren't buffers auto-flushed by default?


I recently had the privilege of setting $| = 1; inside my Perl script to help it talk faster with another application across a pipe.

I'm curious as to why this is not the default setting. In other words, what do I lose out on if my buffer gets flushed straightaway?


Solution

  • Benchmark it and you will understand.

    Buffered depends on the device type of the output handle: ttys are line-buffered; pipes and sockets are pipe-buffered; disks are block-buffered.

    This is just basic programming. It’s not a Perl thing.