alecclews has asked for the wisdom of the Perl Monks concerning the following question:
Now I'd like to access the values for a sub hash in a foreach loop, but only for a given occurrence of 'h1' or 'h2'. e.g.use vars qw($v); $v = ( h1 => { k1 => vh1k1, k2 => vh1k2, } h2 => { k1 => vh2k1, k2 => vh2k2, } )
I've tried all the approaches I can think off but the compiler is never happy that I am passing a hash to keys.my $ofCurrentInterest = 'h1'; foreach $key (keys $v->{$ofCurrentInterest}) { $$key = $v->{ofCurrentInterst}->{$key} }
Does anyone have any tips please?
Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: using keys on hash of hash
by pjf (Curate) on May 22, 2008 at 02:08 UTC | |
|
Re: using keys on hash of hash
by ysth (Canon) on May 22, 2008 at 02:28 UTC | |
|
Re: using keys on hash of hash
by hesco (Deacon) on May 22, 2008 at 02:39 UTC | |
|
Re: using keys on hash of hash
by Herkum (Parson) on May 22, 2008 at 04:40 UTC | |
|
Re: using keys on hash of hash
by moritz (Cardinal) on May 22, 2008 at 08:43 UTC | |
|
Re: using keys on hash of hash
by Anonymous Monk on May 22, 2008 at 02:35 UTC |