http://qs1969.pair.com?node_id=373474


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.