G'day dirtdog,

"perldsc - Perl Data Structures Cookbook" should have all the information you need for this task.

The main problem with the code you show is the declaration and definition of hashes inside the declaration and definition of another hash.

You can write it like this:

my %teams = ( ... ); my %restaurants = ( ... ); my %Businesses = ( teams => \%teams, restaurants => \%restaurants, );

Or like this:

my $teams = { ... }; my $restaurants = { ... }; my %Businesses = ( teams => $teams, restaurants => $restaurants, );

Or like this:

my %Businesses = ( teams => { NFL => { ... }, ... }, restaurants => { FASTFOOD => { ... }, ... }, );

And various other permutations like those. See the doco I linked to for details.

You access values like this:

$Businesses{teams}{NFL}{JETS}

Again, the doco has details.

I also note all your values are just "1". That may have some significance but, if it's only to give each key some arbitrary value, you might be better off with arrays:

... NFL => [ qw{ JETS PATRIOTS GIANTS } ], ...

— Ken


In reply to Re: How to define and deref hash of hash of hash by kcott
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.