in reply to Re^2: Modifying the keys in a hash
in thread Modifying the keys in a hash
How come 'Value2' is changed to 'Value_two', but 'key2' is unchanged?use Data::Dump qw(dump); my %hash = ( key1 => 'Value1', key2 => 'Value2', key3 => 'Value3', ); print "old hash is " . dump(\%hash) ."\n"; map { s/2/_two/; } %hash; print "new hash is " . dump(\%hash) ."\n"; # output is: # old hash is { key1 => "Value1", key2 => "Value2", key3 => "Value3" } # new hash is { key1 => "Value1", key2 => "Value_two", key3 => "Value3 +" }
(Note: I wasn't suggesting that this method should be used for modifying a hash key, but was trying to rise to the challenge of suggesting another method other than copy and delete!)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Modifying the keys in a hash
by shmem (Chancellor) on Feb 23, 2007 at 16:58 UTC |