Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Searching for member of array under doubly nested hash

Posted on 2003-03-20
3
Medium Priority
?
120 Views
Last Modified: 2010-03-05
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
0
Comment
Question by:mwedzi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 300 total points
ID: 8177351
if( grep $_ eq 'x', @{$HashTable{a}{b}} ){
0
 

Author Comment

by:mwedzi
ID: 8178558
Thanks so much! works perfectly, of course.  Are you a boy? Do you have a girl?  Man, programming guys are so hot.
0
 
LVL 84

Expert Comment

by:ozo
ID: 8178620
#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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question