Searching for member of array under doubly nested hash

I'm having trouble determining the code to ask if a value is a member of an array, where the array is the value of a hash which in turn in the value of another hash.  Eg:
%HashTable = (
   "a" => {
      "b" => ['x', 'y', 'z'],
    }
);

I know the code
$HashTable{$a}{$b}->[1]
for example will give me 'y' but I want code that will return true if y or x or z is a member of that array.  I've already tried something like:
$Char = x;
if (exists $HashTable{$a}{$b} -> [$Char]){ . . .
but no luck with that
would really appreciate help.  this little syntax difficulty is keeping me from writing the fst i want.
thanks,

nikki
mwedziAsked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
if( grep $_ eq 'x', @{$HashTable{a}{b}} ){
0
 
mwedziAuthor Commented:
Thanks so much! works perfectly, of course.  Are you a boy? Do you have a girl?  Man, programming guys are so hot.
0
 
ozoCommented:
#If you're going to make lots of member tests like that, you may want to replace your array with a hash:
%HashTable = (
  "a" => {
     "b" => {x=>1,y=>1,z=>1},
   }
);
#then you can use your exists test
if( exists $HashTable{a}{b}{x} )
0
All Courses

From novice to tech pro — start learning today.