Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Looping through Multi Dimensional Hashes

by l2kashe (Deacon)
on Jul 15, 2003 at 14:37 UTC ( [id://274433]=note: print w/replies, xml ) Need Help??


in reply to Looping through Multi Dimensional Hashes

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.....

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://274433]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2024-03-28 12:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found