As a "i just now made this up rule of thumb", use braces when parens won't do. Parens are just a fragile
container for lists, they will flatten by default:
my @one_d = ( (1,2,3), (4,5,6), (7,8,9) );
is really just a single list. You have to use braces:
my @two_d = ( [1,2,3], [4,5,6], [7,8,9] );
I prefer to use a reference to an anonymous array for the outside container, maily because there is no mixing of
parens and braces, square or curly:
my $two_d = [ [1,2,3], [4,5,6], [7,8,9] ];
When in doubt, always consult Data::Dumper. Always! If you had used Data::Dumper on your data structure,
you would have seen that the problem was within it:
print Dumper \@AoH;
__END__
(it's an AoHoH ... not an AoHoAoH)
$VAR1 = [
{
'page' => {
'paragraph' => 'lesson1'
},
'chapter' => 'Basic',
'HASH(0x8638dec)' => undef
},
{
'HASH(0x86fee04)' => undef,
'page' => {
'paragraph' => 'lesson3'
},
'chapter' => 'Advanced'
}
];
Finally, print out a copy of References quick reference. And don't forget about Data::Dumper! :)
|