Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Accessing an AoHoAoH

by CountZero (Bishop)
on Jun 05, 2004 at 19:48 UTC ( [id://361664]=note: print w/replies, xml ) Need Help??


in reply to Accessing an AoHoAoH

Do not assign the reference to your structure to an array (@AoH) but to a scalar. Putting an array creates an extra level of an array in it which you do not need. Use Data::Dumper to see this.

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Replies are listed 'Best First'.
Re^2: Accessing an AoHoAoH
by bradcathey (Prior) on Jun 05, 2004 at 20:05 UTC
    CountZero, not sure I understand. Ran Data::Dumper and got:
    $VAR1 = { 'chapter' => 'Basic', 'page' => [ { 'paragraph' => 'lesson1' }, { 'paragraph' => 'lesson2' } ] }; $VAR2 = { 'chapter' => 'Advanced', 'page' => [ { 'paragraph' => 'lesson3' }, { 'paragraph' => 'lesson4' } ] };
    What am I missing? Thanks

    —Brad
    "A little yeast leavens the whole dough."

      That's what you should get if you write something like dump @AoH; because @AoH "flattens" to a one-element list in the list context of the function call. (This was just a guess, but I'm sure in what I'll write below.)

      This way, however, you can not easily access the contents of the deep datastructure, as you can't index the array in such a way that it flattens automatically, so you have to use a 0 as a first array index, just as CountZero said.

      To change, either use a scalar variable, or (perhaps better) use an array variable, just assign it like @AoH= ({...}, {...}, ...);, not @AoH= [{...}, {...}, ...];.

        Gotcha ambrus. Helpful to know! Thanks

        —Brad
        "A little yeast leavens the whole dough."
      Try print Dump(\@AoH);

      Then you see the extra level of the @AoH array

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://361664]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-19 09:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found