http://qs321.pair.com?node_id=432254


in reply to Looping through a hash where some keys are the same

Does anyone else find it surprising that each returns twice? I would have thought that the second assignment of the duplicate key would overwrite the original, and you only get one key/value pair back.

I appeal to the wise among you...

#!/usr/bin/perl use Data::Dumper; my %h = ( a => 1, a => 2 ); print Dumper \%h; for ( my($k,$v) = each %h ) { print "$k -> $v\n"; } __END__ $VAR1 = { 'a' => 2 }; a -> 2 a -> 2 # why?