in reply to How to extract keyvalue pairs with duplicate values
use strict; my %hash = ( 1 => 'a' , 2 => 'b' , 3 => 'c' , 4 => 'b' , 5 => 'e' , 6 => 'b' , 7 => 'a' , 8 => 'z' ); my %values_with_multiple_keys = (); foreach my $k (keys %hash) { push @{ $values_with_multiple_keys{$hash{$k}} }, $k; } foreach my $m (keys %values_with_multiple_keys) { if (scalar @{$values_with_multiple_keys{$m}} > 1) { print "$m is referenced by: ", join ', ', @{$values_with_multi +ple_keys{$m}}, "\n"; } } ___OUTPUT___ a is referenced by: 7, 1, b is referenced by: 6, 2, 4,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to extract keyvalue pairs with duplicate values
by august3 (Acolyte) on Oct 18, 2004 at 23:52 UTC | |
by pelagic (Priest) on Oct 19, 2004 at 08:45 UTC |