Last active
February 28, 2020 16:47
-
-
Save DRVTiny/3758c139f95e16c62749c63896b66e14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To avoid IO::Handle and other IO::* "autoloading" when using $fh->autoflush(1) | |
sub __autoflush($) { | |
my $fl_have2select = defined(my $fh = $_[0]); | |
# previously selected file handler | |
my $prv_sel_fh; | |
if ( $fl_have2select and ! eval { | |
no warnings; | |
$prv_sel_fh = select $fh; | |
print '' or die "$!\n"; | |
}) { | |
# __out_to_tty '>>', __chomp(\$@), '<<'; | |
defined($prv_sel_fh) and select($prv_sel_fh); | |
return | |
} | |
my $prv_af = $|; | |
my $new_af = ($#_ > 0) && ! $_[1] ? 0 : 1; | |
( !! $prv_af ^ !! $new_af ) and $| = $new_af; | |
$fl_have2select and fileno($prv_sel_fh) != fileno($fh) and select($prv_sel_fh); | |
return $prv_af | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment