in reply to quick question about hash element access
and you would call it like this:sub nested_lookup { my $node = shift; while (ref($node) and @_) { $node = $node->{ shift(@_) }; } return @_ ? undef : $node; }
(Note: could benefit from more error checking.)my $elem = nested_lookup(\%hash, split /\./, 'a.b.c.d');
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: quick question about hash element access
by Chmrr (Vicar) on Jun 28, 2003 at 01:11 UTC |