in reply to Matching value in hash help!

Your hash is inside out.

my %locs_by_wind_dir; for my $loc (keys(%wind_dir)) { for my $wind (split /,/, $wind_dir{$loc}) { push @{ $locs_by_wind_dir{$wind} }, $loc; } } print("$_\n") for @{ $locs_by_wind_dir{'AE'} }; # Loc A, Loc B

Replies are listed 'Best First'.
Re^2: Matching value in hash help!
by Anonymous Monk on Sep 24, 2010 at 02:06 UTC
    What do you mean by "Your hash is inside out."?

      It means that, in the hash you're currently using, the values you're looking for are in keys, and the keys you're searching with are in values.

      More useulf is a hash that looks like the following:

      AA => "Loc A", BB => "Loc A", TT => "Loc B", T => "Loc B", PP => "Loc C", # etc
      Compare the output of the following
      use Data::Dumper qw( Dumper ); print(Dumper(\%wind_dir)); print(Dumper(\%locs_by_wind_dir));