in reply to flushing a filehandle in PurePerl
print $fh q{}; is not needed. Turning autoflush on causes an immediate flush.
$|++ is misleading. It implies $|-- will turn off autoflush, but it doesn't always. Be clear and use $| = 1 instead.
local $|++; is a compile error. ("Can't modify postincrement (++) in local".)
My tests shows that local $|; won't do what you think on block exit. It will set the autoflush flag for whichever file handle is selected when the blocks exits. That's the wrong handle.
Use this:
sub flush { my $osh = select($_[0]); my $oaf = $|; $| = 1; $| = $oaf; select($osh); return 1; }
Update: Added last two bullets and the code snippet.
|
|---|