in reply to Modifying hash keys via aliasing
Admittedly, it is not quite exactly the same, but you don't need a sub to figure out that you simply cannot modify the keys of a hash (other than by deleting an existing entry and creating another one.
What is happening in your sub is that the values associated with the hash keys are actually modified in @_, but this has no effect on the hash itself, whereas the values associated with the hash values are actually modified within the hash, as it can be seen with this slight modification of your one-liner:
$ perl -MData::Dumper -we 'sub t{ $_+=1 for @_; print Dumper \@_;} my + %h = (1 => 2, 3 => 4); t(%h); print Dumper \%h' $VAR1 = [ 2, 3, 4, 5 ]; $VAR1 = { '1' => 3, '3' => 5 };
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Modifying hash keys via aliasing
by Discipulus (Canon) on Aug 11, 2015 at 09:41 UTC | |
by Laurent_R (Canon) on Aug 11, 2015 at 11:51 UTC |