Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Pass by value acts like pass by reference

by sauoq (Abbot)
on Jul 11, 2004 at 20:15 UTC ( #373509=note: print w/replies, xml ) Need Help??


in reply to Pass by value acts like pass by reference

When you copy the hash with my %hash = @_; you are making copies of its values, but those values are themselves references. And the copied references refer to the same things that the originals do!

In order to get pass-by-value like behavior¹ with complex structures in Perl, you need to make a "clone" or "deep copy" of your structures. The Storable module can help with that.

1. I say "pass-by-value like behavior" because, regardless, the actual passing to your subs is really by reference. You must make the copy yourself.

-sauoq
"My two cents aren't worth a dime.";

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2023-02-06 06:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (33 votes). Check out past polls.

    Notices?