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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |