Roboz has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing SOAP::Lite results
by shmem (Chancellor) on Sep 28, 2012 at 10:18 UTC | |
by Roboz (Novice) on Sep 28, 2012 at 10:52 UTC | |
by kcott (Archbishop) on Sep 28, 2012 at 12:28 UTC | |
|
Re: Parsing SOAP::Lite results
by Anonymous Monk on Sep 28, 2012 at 10:32 UTC | |
by Roboz (Novice) on Sep 28, 2012 at 10:57 UTC | |
|
Re: Parsing SOAP::Lite results
by kcott (Archbishop) on Sep 28, 2012 at 10:38 UTC | |
by Roboz (Novice) on Sep 28, 2012 at 11:14 UTC | |
by kcott (Archbishop) on Sep 28, 2012 at 12:05 UTC | |
by Roboz (Novice) on Sep 28, 2012 at 12:52 UTC | |
by kcott (Archbishop) on Sep 28, 2012 at 13:21 UTC | |
| |
by Anonymous Monk on Sep 28, 2012 at 12:57 UTC | |
by 2teez (Vicar) on Sep 28, 2012 at 12:16 UTC | |
|
Re: Parsing SOAP::Lite results (walking/navigating/iterating over)
by Anonymous Monk on Sep 28, 2012 at 10:41 UTC | |
by Roboz (Novice) on Sep 28, 2012 at 11:19 UTC |