in reply to Re: Re: Strange method behavior
in thread Strange method behavior

The original hash was getting changed because all your references pointed to that hash. The thing to remember is that when you derefence a reference, you get the original data structure back, not a copy of the structure. To get a copy, you need to make the copy when you create the reference.
my %hash = (snark => 'snark'); # hash my $ref = \%hash; # ref to hash surprise($ref); # pass ref to hash sub surprise { my $ref = shift; # copy ref to hash $ref->{snark} = 'boojum'; # change ref'ed hash } print "snark => $hash{snark}\n"; # print original hash __END__ snark => boojum