http://www.perlmonks.org?node_id=239820


in reply to Tear it apart...select()

As the originator of that meme, let me apologize for that, right alongside my apology for originally promoting the use of grep in a void context purely for its side effects, and for originating the concept of a JAPH, which tends to lead non-Perl hackers to believe that Perl is only about obscurity.

I'm sorry.

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

Replies are listed 'Best First'.
Re^2: Tear it apart...select()
by Aristotle (Chancellor) on Mar 02, 2003 at 13:38 UTC
    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.

      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.

Re: Re: Tear it apart...select()
by snafu (Chaplain) on Mar 02, 2003 at 05:50 UTC
    But that is one of the coolest things about Perl!!! =P It keeps me on my toes!

    _ _ _ _ _ _ _ _ _ _
    - Jim
    Insert clever comment here...