Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Cheap idioms

by demerphq (Chancellor)
on Oct 14, 2002 at 11:07 UTC ( #205031=note: print w/ replies, xml ) Need Help??


in reply to Cheap idioms

On the subject of cheap idioms...

select( ( select(STDOUT), $| = 1 )[0] );
Took me a few minutes to work out, but I like it, a lot actually.

:-)

--- demerphq
my friends call me, usually because I'm late....


Comment on Re: Cheap idioms
Download Code
Re: Re: Cheap idioms
by Juerd (Abbot) on Oct 14, 2002 at 14:16 UTC

    select( ( select(STDOUT), $| = 1 )[0] );

    This only works if the inner select is evaluated before the assignment is, and I can't find any specification of evaluation order (remember ++$a, $a++, ++$a?)

    That's why I don't dare to use this idiom, although I see it often. I still prefer STDOUT->autoflush(1) (using IO::Handle). It's shorter too :)

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

      Ah, but you're wrong. In a simple list, as perlop explicitly states, operands are evaluated left-to-right. Otherwise, you couldn't write print("Done.\n"), exit if $done;

      either, but we all know that it works, right? Your example is problematic because is uses pre- and postincrement operators which mess with the order of side effects.

      IO::Handle loads over 1,000 lines of code - if it's just for a single autoflush, what's the point? Especially seeing as the select idiom is known and even delivered with the perldocs, it's safe to assume it isn't cryptic.

      Makeshifts last the longest.

        Im sorry but I fail to understand how both these idioms work. I can see why it slurps a file, but cant really say exactly how... Could somebody explain the magic with ARGV?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2014-07-11 09:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (223 votes), past polls