http://qs321.pair.com?node_id=280165


in reply to Re: Re: Perl Idioms Explained - $|++
in thread Perl Idioms Explained - $|++

In larger scripts, I simultaneously handle that and the clarity issue by writing code like this
001 use IO::Handle; 002 STDOUT->autoflush;

I got kinda turned off of IO->Handle when I read this comment in the pod

use IO::Handle; # thousands of lines just for autoflush :-(

When I read the authors name, it strengthened the feeling.

Update: To clarify, the author to which I referred was the author of the comment I quoted above--from the pod of perlipc not IO->Handle--Tom Christiansen, who comments are to be valued.

I have absolutely nothing against Graham Barr (the author of IO::Handle), nor even much against that module.

My only reservation was of the practice of using IO->Handle only for the purposes of turning on autoflush.

If $|=1; $|=0; is deemed to cryptic, you could use something like:

sub autoflush (*$) { # Set the state of autoflush for # the handle supplied as $_[0] # to the boolean state supplied as $_[1] select( do{ my $old = select( $_[0] ); $| = $_[1]; $old; } ) } ... autoflush( STDOUT, 1 ); # autoflush on ... autoflush( STDOUT, 0 ); # autoflush off

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.