Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^5: ternary conditional help (alias)

by tye (Sage)
on Nov 28, 2016 at 21:39 UTC ( [id://1176742]=note: print w/replies, xml ) Need Help??


in reply to Re^4: ternary conditional help
in thread ternary conditional help

Well, I would characterize the reason as having more to do with the fact that passing $a = 2 as an argument causes an alias to $a to be put into @_. Had a copy of $a's value been placed into @_ instead, then subsequently changing $a to 3 would not impact that copy.

print $a = 1, 0+$a, $a = 2, 0+$a, $a = 3, 0+$a; # prints "313233"

The reason that $a = 2 passes an alias is because it is an "lvalue" expression, which just means that you can do previously mentioned things like ( $a = 2 ) = 3. And the reason that lvalue expressions cause aliases to be passed is two-fold: So you can modify arguments via code like $_[0] = 3 in your sub and because it is more efficient than creating a copy.

- tye        

Log In?
Username:
Password:

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

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

    No recent polls found