Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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....

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://205031]
[choroba]: I loved McVitie's, but stopped buying them when they started using palm oil
[1nickt]: ++choroba for walking the walk
[choroba]: My children don't want to eat "dead monkey" biscuits

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2017-11-20 13:02 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (286 votes). Check out past polls.