Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: &&= vivify keys?

by Eliya (Vicar)
on Apr 18, 2012 at 09:06 UTC ( #965678=note: print w/ replies, xml ) Need Help??

in reply to &&= vivify keys?

$x{a} &&= 1; is effectively the same as

$x{a} = $x{a} && 1;

which is in this case

$x{a} = undef && 1;

which is

$x{a} = undef;

Comment on Re: &&= vivify keys?
Select or Download Code
Replies are listed 'Best First'.
Re^2: &&= vivify keys?
by oha (Friar) on Apr 18, 2012 at 09:10 UTC
    so true!

    not sure why, but i was expecting it to be the same as

    $x{a} && $x{a} = 1;
    thank you!

      Actually, you're closer to the truth than Eliya is. The assignment is indeed conditional.

      Aside from the syntax error from missing parens, the problems both yours and Eliya share are:

      • 1 is actually evaluated before anything else,
      • $x{a} is only evaluated once, and
      • $x{a} is (only) evaluated in lvalue context.

      See Re^2: &&= vivify keys?.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2015-11-29 05:27 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (747 votes), past polls