in reply to Have hash of arrays. Want to test if variable is a member of any of the arrays
use warnings; use strict; use List::MoreUtils qw(any); my %hoa = ( x => [ qw(a b c d) ], y => [ qw(e f g) ], z => [ qw(h i c j) ], ); my $x = 'c'; for my $k (keys %hoa) { print "key $k has $x\n" if any { $_ eq $x } @{ $hoa{$k} }; } __END__ key x has c key z has c
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Have hash of arrays. Want to test if variable is a member of any of the arrays
by tobyink (Canon) on Dec 13, 2014 at 20:08 UTC | |
by toolic (Bishop) on Dec 13, 2014 at 21:20 UTC |