OK, I'm re-asking this question in a more succinct, focused manner (I hope.) I'm trying to parse a SOAP::Lite result data structure. Here's an example:

$VAR1 = { 'Toys' => bless( { 'Toy' => [ bless( { 'ToyLocations' => bless( { 'ToyLocation' => [ { 'toyQuantity' => '1', 'locationName' => 'toybox' }, { 'toyQuantity' => '4', 'locationName' => 'shelf' } ] }, 'ArrayOfToyLocation' ), 'color' => 'none', 'toyName' => 'Sorry', 'size' => 'medium' }, 'Board' ) ] }, 'ArrayOfToy' ) };

I'd like to list the locations and quantities along with the name from the parent node. When I parsed the data with only a single location the following code worked:

foreach my $e (@{$getToysResults->{Toys}{Toy}}){ print "$e->{ToyLocations}{ToyLocation}{locationName}\n"; }

But it errored with "Not a HASH reference" when there was more than one location. That's when I realized I had to use nested foreach statements to do what I needed. BUT I can't figure out how to get at the list of locations! I've tried the following:

foreach my $e (@{$getToysResults->{Toys}{Toy}{ToyLocations}{ToyLocatio +n}}){ print "$e->{locationName}\n"; }

and I get a 'Not an ARRAY reference' error. What am I doing wrong?


In reply to Parsing SOAP::Lite results by Roboz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.