Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Cheap idioms

by demerphq (Chancellor)
on Oct 14, 2002 at 11:07 UTC ( [id://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....

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://205031]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found