Based on (tye)Re: varying length multi-dimensional hashes:
Note that you can return $ref; instead of $$ref if you want to modify the indicated value instead of just fetching it. - tyesub derefHashTree { my( $hv, @keys )= @_; my $ref= \$hv; for my $key ( @keys ) { $ref= \$$ref->{$key}; } return $$ref; } my %hash1; $hash1{key1}{key2}{key3}{A} = "hello"; $hash1{key1}{key2}{key3}{B} = "bye"; my $new_hash = \%hash1; my @keys= qw( key1 key2 key3 ); foreach( keys %{ derefHashTree($new_hash,@keys) } ) { print "$_\n"; }
In reply to Re: eval on hash (use \\)
by tye
in thread eval on hash
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |