Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Tear it apart...select()

by Aristotle (Chancellor)
on Mar 02, 2003 at 13:38 UTC ( [id://239849]=note: print w/replies, xml ) Need Help??


in reply to •Re: Tear it apart...select()
in thread Tear it apart...select()

I understand the apologies for grepping in void and the concept of the JAPH, but why do you apologize for the select idiom?

Makeshifts last the longest.

Replies are listed 'Best First'.
•Re: Re^2: Tear it apart...select()
by merlyn (Sage) on Mar 02, 2003 at 15:02 UTC
    Well, the post was all tongue in cheek, but to break character here, the select() idiom was something I came up with one day when I was trying to unbuffer an arbitrary filehandle, regardless of the currently selected filehandle. Since I had invented the literal slice notation, I wondered if that could be used there to eliminate the normal temporary variable by holding the previous handle as part of the constructed list. And boom, there it was.

    The problem is that its obscurity offsets any useful gain over just writing it as a normal two or three step process.

    Another way to do it without using a "temporary" variable might be something like:

    for (select(HANDLETOUNBUFFER)) { $|++; select($_); }
    But I'd argue this is just as obscure.

    Moral of the story: it's ok to say my $old = select(NEW); when you need the old handle. It's fine. Don't worry. Be happy.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      I guess you can take a middle road with an explicit temporary with something like
      select(do { my $oldfh = select(FH); $|++; $oldfh });
      That's not too verbose and seems less obscure to me. The inevitable temporary is at least confined to a microscopic block.

      Makeshifts last the longest.

        Well, that still makes it inside out, and also introduces a do block, which is not necessarily obvious.

        The obvious approach that reads nicely and keeps a confined temp var is:

        { my $old = select NEW; $|++; select $old }
        No fuss, no muss. Reads left to right. Says what it does.

        -- Randal L. Schwartz, Perl hacker
        Be sure to read my standard disclaimer if this is a reply.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-25 10:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found