First of all you should be using strict & warnings (I Think you are not) as you are not declaring your variables with 'my' or 'our'
Anyway, Something like t his might work for you.
my %families = ( flintstones => { father => "fred", mother => "willma", kid => "bambam", }, simpsons => { father => "homer", mother => "marge", kid => "bart", }, ); print getfamily(\%families,'bart','kid'); sub getfamily { my ($families,$member,$type) = @_; foreach my $family ( keys %{ $families } ) { while ( my ($status,$name) = each %{ $families{$family} } ) { if ( $status eq $type && $member eq $name ) { return $family; } } } return undef; }
Update: Modified code to account for status as per bobf replay.
I'll leave it to the OP to choose what he wants to do with duplicates.
In reply to Re: Finding hashes in hashes of hashes
by ahmad
in thread Finding hashes in hashes of hashes
by cyphy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |