So you want a single hash with all the data? This code shows how, then it goes on to extract all the way down to the teams and their values. Similar code would be used to iterate over the restaurants. It's technically a hash of hashes of hashes.

use warnings; use strict; my %hoh = ( restaurants => { fast => { mcd => 1, wendys => 1, }, fine => { keg => 1, grill => 1, }, }, teams => { nfl => { pats => 1, falcons => 1, }, nhl => { maple_leafs => 1, flames => 1, }, }, ); my $team_href = $hoh{teams}; for my $league (keys %$team_href){ print "$league\n"; for my $team (keys %{ $team_href->{$league} }){ print "\t$team: $team_href->{$league}{$team}\n"; } } # get one team # ... are the Leafs going to win the cup this year? print "$hoh{teams}->{nhl}{maple_leafs}\n";

Output:

nfl falcons: 1 pats: 1 nhl flames: 1 maple_leafs: 1 1

In reply to Re: How to define and deref hash of hash of hash by stevieb
in thread How to define and deref hash of hash of hash by dirtdog

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.