Each hash has just one iterator aligned to itself in Perl (see each). Therefore, running each
for the same hash in a loop that calls each
is not doing what you think.
If you want to see what's going on, try adding the following line at the start of the outer loop:
warn $k;
You are missing several dollar signs before variable names. For example, you probably want to delete $hashmap{$k}
instead of $hashmap{k}
, which is equivalent to $hashmap{'k'}
.
To output an array of arrays, you have to dereference the inner arrays:
print map "@$_\n", @dupsarray;
BTW, I would use a hash of arrays to solve your task. Here's how:
my %dups;
while (my ($k, $v) = each %hashmap) {
push @{ $dups{$v} }, $k;
}
for my $k (grep @{ $dups{$_} } > 1, keys %dups) {
print "$k: @{ $dups{$k} }\n";
}