in reply to Getting the keys of identical values in a hash

Invert the hash, putting keys in anonymous arrays,

my %hash = {1 => 'One', 2 => 'Two', 3 => 'One'}; my %ihash; push @{$ihash{$hash{$_}}}, $_ for keys %hash; print "@{$hash{One}}\n";

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: Getting the keys of identical values in a hash
by QM (Parson) on Sep 14, 2005 at 13:50 UTC
    And then check for keys whose anonymous array has more than one value:
    my @same_value_keys = grep { @{$_} > 1 } values %ihash;
    where each array element is itself an array of keys with the same value in the original hash.

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of