Thursday, February 17, 2011

how to get keys from hash values

%hash = ("one"=>1, "two"=>2, "three"=>3, "four"=>4, "one1"=>1, "six"=>6, "three1"=>3);
@value = values %hash;
@key = keys %hash;

@dup = grep {$hash{$_}++} @value;
foreach (@dup) {
    for($i=0; $i < $#value; $i++) {
        if($_ == $value[$i]) {
            print "$key[$i]\n";
        }
    }
}

No comments: