_find()
- We have a data structure, of arbitrarily nested hash and array refs
- The find method gives us a reference to a reference into that data structure
sub _find {
# Return a reference to the reference
# that points to the hash-ref
# that contains the desired item.
my $menu = shift;
my $descRE = shift;
foreach my $entry (@$menu) {
next if ref($entry) eq 'ARRAY';
if (defined $entry->{menu}) {
# recursive call to _find
my $found = _find($entry->{menu}, $descRE);
return $found if $found;
}
return \$entry
if $entry->{desc} =~ $descRE;
}
}