#!/usr/bin.perl #hashes of hashes test.pl %HoH = ( flintstones => { lead => "fred", pal => "barney", }, jetsons => { lead => "george", wife => "jane", "his boy" => "elroy", }, simpsons => { lead => "homer", wife => "marge", kid => "bart", }, ); #endhoh # print the whole thing foreach $family ( keys %HoH ) { print "$family: { "; for $role ( keys %{ $HoH{$family} } ) { print "$role=$HoH{$family}{$role} "; } print "}\n"; } #print one family (which is a hash) and assign it to a hash print " print family simpsons\n"; $family ='simpsons'; for $role ( keys %{ $HoH{$family} } ) { print "\t$role=$HoH{$family}{$role} "; $simpsons{$role}=$HoH{$family}{$role}; #this works } print "}\n"; print "lead simpsons is: $simpsons{lead}\n"; #assign the families to a hash %newsimpsons = %{ $HoH{$family} }; #this works but you must provide a value for $family %jetsons = %{ $HoH{'jetsons'} }; #this works but you must provide a value in $HOH{'value'} "which can be a string print "lead simpsons is: $newsimpsons{lead}, lead jetsons is $jetsons{lead}\n";