snape has asked for the wisdom of the Perl Monks concerning the following question:
If you have a hash of hashes and you want to iterate across all values, what's the best way to do it. I would like to know if I coule iterate through Hash of hashes without using foreach twice (or number of times hashes are present). For example, I would like to do:
foreach my ($key1, $key2) (keys %hoh) { ### CODE ### }
instead of
foreach my $key1 (keys %hoh) { foreach $key2 (keys %{$hoh{$key1}) { ### CODE ### } }
I hope there is some way to do it. Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Traversing through HoH
by aaron_baugher (Curate) on Apr 04, 2012 at 21:22 UTC | |
|
Re: Traversing through HoH
by tangent (Parson) on Apr 04, 2012 at 23:43 UTC | |
|
Re: Traversing through HoH
by BrowserUk (Patriarch) on Apr 04, 2012 at 21:21 UTC | |
|
Re: Traversing through HoH
by Anonymous Monk on Apr 04, 2012 at 21:45 UTC | |
by snape (Pilgrim) on Apr 05, 2012 at 00:08 UTC | |
by Anonymous Monk on Apr 05, 2012 at 01:20 UTC |