in reply to Hash value, containing a reference to some value of hash, not the intended behaviour.

however, after first iteration, modification in %newhash also modifies %hashcopy. I am not able to understand the reason behind such behaviour in nested hashes. Please help!

Its simple, it boils down to

my %newhash; my %hashcopy; my %other; $hashcopy{something} = \%other; $newhash{something} = \%other;
$newhash{something} and $hashcopy{something} are the same thing, a reference to %other;
  • Comment on Re: Hash value, containing a reference to some value of hash, not the intended behaviour.
  • Download Code

Replies are listed 'Best First'.
Re^2: Hash value, containing a reference to some value of hash, not the intended behaviour.
by rakeshrocks (Initiate) on Mar 14, 2011 at 11:24 UTC
    Got it! made a deep copy to make things work