Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How to preserve values outside a sub

by RMGir (Prior)
on Oct 25, 2017 at 15:52 UTC ( [id://1202016]=note: print w/replies, xml ) Need Help??


in reply to How to preserve values outside a sub

That's the way references work - what you're passing to your 'pass1' function is a pointer to the hash '$hashref' points to, not a copy of it, so local changes get applied to that global copy. If you want to pass a local copy, specify that:
pass1({ params => {%$hashref} }); # {%$hashref} makes a (shallow) cop +y of the hash '$hashref' # points to and creates a new ref t +o it.
If you do that, then you get:
before pass1: 1 Inside pass1... 2 3 after pass1: 1
which is what I think you expect.

Added (shallow) note, AnomalousMonk is correct in his reply below!


Mike

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-19 01:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found