in reply to changing copy of a hash changes original

The problem is the hash copy because it's a shallow copy. %hash1 and %hash2 have a key by the name of 'Quantity' which happen to point to the same thing...namely {x=>1,x=>2}. In fact the fidleHash() sub doesn't change the hash which comes in as an argument, rather it changes the hash which the 'Quantity' key is pointing to. Insert the following two lines after copying the hash: my %hashCopy = %{$hash1{'Quantity'}} ; $hash2{'Quantity'} = \%hashCopy ; ...and you won't see the problem anymore. That way you also create a copy of what 'Quantity' points to.
  • Comment on Re: changing copy of a hash changes original