Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

by saintmike (Vicar)
on Mar 04, 2007 at 21:27 UTC ( [id://603134]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Why are "a ||= b" and "a = a || b" different?
in thread Why are "a ||= b" and "a = a || b" different?

Thanks, diotalevi, your explanation of the side effects makes perfect sense.

Do you have any thoughts about why

($ret1, $ret2) ||= foo();
refreshes $ret2 and not $ret1 with the result of the evaluation of foo() in scalar context as mentioned by varian ?

Update: typo fixed, thx diotalevi.

Replies are listed 'Best First'.
Re^5: Why are "a ||= b" and "a = a || b" different?
by diotalevi (Canon) on Mar 04, 2007 at 22:18 UTC

    You have a typo and meant ||= instead of =||.

    In the case of (A,B) ||= C, (A,B) || ... is the comma operator in scalar context. It evaluates the left argument A, then the right argument B and returns B. Thus you've just written A; B ||= C;.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      D'oh! :). Thanks for clarifying.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-25 20:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found