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

Re: Pass by value acts like pass by reference

by Anonymous Monk
on Jul 11, 2004 at 16:42 UTC ( #373474=note: print w/replies, xml ) Need Help??


in reply to Pass by value acts like pass by reference

Thank you for the reply but I think you missunderstood my question. I passed by value, a flattened list of key value pairs, but after the transformation of the temporary hash in the sub, the hash outside the sub reflects the changes. I've been thinking further though and think what may be happening is that what is passed to the sub is a array reference. And inside the sub, 1 is pushed onto this array, which is the same array contained in the hash outside the sub. So thats why the change is noted (I think). Is this correct?
  • Comment on Re: Pass by value acts like pass by reference

Replies are listed 'Best First'.
Re^2: Pass by value acts like pass by reference
by demerphq (Chancellor) on Jul 11, 2004 at 19:30 UTC

    When you flatten a hash you are getting a shallow copy of the hash, not a deep copy. To get a deep copy you need to use some form of serialization mechanism to do it. Storable will probably be your best bet in terms of speed and memory consumption. Of course,it may be a lot easier to just change your algorithm to not corrupt the original arrays....


    ---
    demerphq

      First they ignore you, then they laugh at you, then they fight you, then you win.
      -- Gandhi


      Of course,it may be a lot easier to just change your algorithm to not corrupt the original arrays....

      That was what I ended up doing, thanks to to tilly's suggestion. Thank you to all who responded.

Re^2: Pass by value acts like pass by reference
by tilly (Archbishop) on Jul 11, 2004 at 16:43 UTC
    This is exactly what is happening.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2023-01-27 15:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?