Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Re: Short Circuit Operator and Hash Assignment

by dada (Chaplain)
on Mar 17, 2004 at 17:25 UTC ( #337428=note: print w/replies, xml ) Need Help??


in reply to Re: Short Circuit Operator and Hash Assignment
in thread Short Circuit Operator and Hash Assignment

The 1 && part is being optimized out of the statement.
this seems a rather dangerous and naive optimization to me, given that also this:
$x = 1 && $y = 2; $x = 0 || $y = 2;
gets "optimized" as:
$x = $y = 2; $x = $y = 2;
perhaps the p5p people should do something about it.

cheers,
Aldo

King of Laziness, Wizard of Impatience, Lord of Hubris

Replies are listed 'Best First'.
Re: Short Circuit Operator and Hash Assignment
by jonadab (Parson) on Mar 17, 2004 at 18:24 UTC
    this seems a rather dangerous and naive optimization to me

    The optimization is a red herring; it's not changing the result in any way. If the left operand of the && operator is true in boolean context, then it returns the value of its right operand, whatever that may be. Expecting it to return the left operand is wrong. (What you really were expecting is a different parse, based on different operator precedence. (See my other post downthread.))


    ;$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$;[-1]->();print
Re: Re: Re: Short Circuit Operator and Hash Assignment
by hardburn (Abbot) on Mar 17, 2004 at 17:33 UTC

    You're hitting an edge case. The optimization had a different situation in mind:

    if( 1 && foo() ) { . . . } elsif( 0 || bar() ) { . . . }

    This optimization is hardly unique to Perl. I believe both C and Java compilers will optimize away constants in exactly the same way.

    ----
    : () { :|:& };:

    Note: All code is untested, unless otherwise stated

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2022-01-21 11:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (57 votes). Check out past polls.

    Notices?