in reply to Referencing a HoH

Here is the code which will help you to understand HOH
use Data::Dumper; $hash{a1}{b1} = 'c1'; $hash{a1}{b2} = 'c2'; $hash{a2}{b1} = 'c3'; $hash{a2}{b3} = 'c4'; print Dumper(\%hash); foreach $key (keys %hash){ print "Key:\t$key\n"; my %subHash = %{$hash{$key}}; print "\tSubkeys:"; foreach $subkey (keys %subHash){ print "\t$subkey"; } print "\n"; }
__END__
$VAR1 = {
          'a2' => {
                    'b1' => 'c3',
                    'b3' => 'c4'
                  },
          'a1' => {
                    'b1' => 'c1',
                    'b2' => 'c2'
                  }
        };  

Key:    a2
        Subkeys:        b1      b3
Key:    a1
        Subkeys:        b1      b2

Replies are listed 'Best First'.
Re: Re: Referencing a HoH
by P0w3rK!d (Pilgrim) on May 07, 2003 at 18:11 UTC
    Thank you. I have not written any Perl with hashes for about 6 months. I simply forgot the %. Shame on me :{
      You could also consider the now mostly disused pseudo-multi-dimensional array syntax:
      $h{$key1,$key2} = $val; while (my ($key, $val) = each %h) { my ($key1, $key2) = split /$;/, $key; print "$key1;$key2 -> $val\n"; }