in reply to Re^2: Accessing an AoHoAoH
in thread Accessing an AoHoAoH

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! :)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re^4: Accessing an AoHoAoH
by bradcathey (Prior) on Jun 05, 2004 at 20:03 UTC
    Great rule of thumb, jeffa. BTW, you have this knack for catching me with my zipper down. I always use Data::Dumper...er...almost all time. Thanks for the reminder to use it all the time and for the Quick Ref.

    —Brad
    "A little yeast leavens the whole dough."
Re^4: Accessing an AoHoAoH
by Jasper (Chaplain) on Jun 07, 2004 at 09:52 UTC
    As a "i just now made this up rule of thumb", use braces when parens won't do.

    I think I'd rather the rot was "try braces when parens didn't do what you thought they would".

    Ditto for curlies and parens when dealing with hashes. Although looking at why, maybe with Data::Dumper, as you say, or looking at what perl told us when we tried to run the thing!!!, is always best. Otherwise we might as well be monkeys bashing away at our keyboards.