in reply to How to define and deref hash of hash of hash

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

Replies are listed 'Best First'.
Re^2: How to define and deref hash of hash of hash
by dirtdog (Monk) on Feb 07, 2017 at 20:51 UTC

    thanks guys...it works like a charm