Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: Why are "a ||= b" and "a = a || b" different?

by diotalevi (Canon)
on Mar 03, 2007 at 18:45 UTC ( [id://603076]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    # (a) could change entirely if run multiple times
    ( rand < .5 ? $a : $b ) = ( rand < .5 ? $a : $b );
    
    ...
    # (a) might have side effects
    tie $a, ...;
    ($a) = $a || foo();
    
  2. or download this
    perl -MO=Concise -e '($a) ||= foo()' | idealized-optree
    
    leave
    ...
                entersub # foo()
                      pushmark
                         gv # *foo
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-20 02:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found