in reply to eval on hash
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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: eval on hash (use \\)
by Anonymous Monk on Apr 09, 2003 at 17:51 UTC | |
by tye (Sage) on Apr 09, 2003 at 18:06 UTC | |
by dragonchild (Archbishop) on Apr 09, 2003 at 17:53 UTC |