in reply to How to define and deref hash of hash of hash
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
|
|---|