The documentation for IPC::Open3 states:
The CHLD_IN will have autoflush turned on
But nothing in the source code mentions IO::Handle::autoflush
. What mechanism does the module use to turn on autoflush for CHLD_IN
?
Buffering is disabled with the following line
select((select($handles[0]{parent}), $| = 1)[0]); # unbuffer pipe
which could be rewritten as
my $old_fh = select($handles[0]{parent});
$| = 1;
select($old_fh);
The traditional way to disable output buffering in Perl is via the $|
variable. From man perlvar
:
- HANDLE->autoflush( EXPR )
- $OUTPUT_AUTOFLUSH
- $|
If set to nonzero, forces a flush right away and after every write or print on the currently selected output channel. Default is 0 (regardless of whether the channel is really buffered by the system or not; $| tells you only whether you've asked Perl explicitly to flush after each write). STDOUT will typically be line buffered if output is to the terminal and block buffered otherwise. Setting this variable is useful primarily when you are outputting to a pipe or socket, such as when you are running a Perl program under rsh and want to see the output as it's happening. This has no effect on input buffering. See getc for that. See select on how to select the output channel. See also IO::Handle.
Mnemonic: when you want your pipes to be piping hot.
Setting $|
acts on "the currently selected output channel" which is set with the one-argument form of select
.