Help for this page

Select Code to Download


  1. or download this
    for my $key (keys %hash) {
        print "$key\n"
            if grep {$_ eq "banana"} @{ $hash{$key} };
    }
    
  2. or download this
    # convert
    my %hoh = map {
    ...
    for my $key (keys %hoh) {
        print "$key\n" if $hoh{$key}{$search};
    }
    
  3. or download this
    # build inverse hash, if all values are unique
    my %inverse_hash;
    ...
    
    # lookup is simple!
    print $inverse_hash{banana}, "\n";
    
  4. or download this
    # convert to "inverse" hash of arrays (in two steps)
    my %hoa;
    ...
    
    # lookup
    print join(', ', @{ $hoa{banana} } ), "\n"