Davorg's post above is on point, but here is how I deal with datastructures like this. Basically I localize a hash ref, to make the code slightly more visually appealing, ala..
for ( keys %category_hash ) {
my $first_lvl = $category_hash{$_};
print "$_\n";
for ( keys %{ $first_lvl } ) {
my $second_lvl = $first_lvl->{$_};
print ' ' x 3 . "$_"\n";
for ( keys %{ $second_lvl } ) {
print ' ' x 6 . "$_ : $second_lvl->{$_}\n";
}
} # END for keys $first_lvl
} # END for keys %category_hash
Grabbing a ref to the hash will be slightly better than creating a copy of the sub hashes as you go along. Personally I think it might be better to define a better structure like recommended above.
Regards
MMMMM... Chocolaty Perl Goodness.....
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.