Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Re: Re: Perl Idioms Explained - $|++

by BrowserUk (Patriarch)
on Aug 01, 2003 at 21:45 UTC ( [id://280165]=note: print w/replies, xml ) Need Help??


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.

Replies are listed 'Best First'.
Re: Re: Re: Re: Perl Idioms Explained - $|++
by sauoq (Abbot) on Aug 01, 2003 at 23:51 UTC
    My only reservation was of the practice of using IO->Handle only for the purposes of turning on autoflush.

    I agree. I said "longer scripts" and most of my longer scripts already pull use IO::Handle somewhere along the line anyway. I probably should have said that it's not a good idea to use it just for autoflush.

    -sauoq
    "My two cents aren't worth a dime.";
    

      Here's intriguing:) ??

      perl -e"autoflush STDOUT, 1;" Can't locate object method "autoflush" via package "IO::Handle" at -e +line 1.

      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.

        This will clear that up some:

        $ perl -le 'print ref *STDOUT{IO}' IO::Handle

        The note in the BUGS section of the IO::Handle pod is explanatory too:

        BUGS Due to backwards compatibility, all filehandles resemble object +s of class "IO::Handle", or actually classes derived from that class +. They actually aren't. Which means you can't derive your own class f +rom "IO::Handle" and inherit those methods.

        -sauoq
        "My two cents aren't worth a dime.";
        

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://280165]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-20 03:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found