in reply to Re^4: Parsing SOAP::Lite results
in thread Parsing SOAP::Lite results
You can use ref to do that.
Here's a modification of my earlier script to show this. For illustration purposes, I've made minor changes to the locationName values so you can see which toybox is being referred to.
#!/usr/bin/env perl use strict; use warnings; my $getToysResults = { 'Toys' => bless( { 'Toy' => [ bless( { 'ToyLocations' => bless( { 'ToyLocation' => { 'toyQuantity' => '2', 'locationName' => 'HASH:toybox +' } }, 'ArrayOfToyLocation' ), 'color' => 'brown', 'toyName' => 'bear', 'size' => 'large' }, 'Stuffed' ), bless( { 'ToyLocations' => bless( { 'ToyLocation' => [ { 'toyQuantity' => '1', 'locationName' => 'ARRAY:toybo +x' }, { 'toyQuantity' => '4', 'locationName' => 'ARRAY:shelf +' } ] }, 'ArrayOfToyLocation' ), 'color' => 'none', 'toyName' => 'Sorry', 'size' => 'medium' }, 'Board' ) ] }, 'ArrayOfToy' ) }; foreach my $e (@{$getToysResults->{Toys}{Toy}}) { my $location_ref = $e->{ToyLocations}{ToyLocation}; my $location_array_ref = ref($location_ref) eq 'ARRAY' ? $location_ref : [ $location_ +ref ]; for my $location_array_hash_ref (@$location_array_ref) { print $location_array_hash_ref->{locationName}, "\n"; } }
Output:
$ pm_parse_soap_ref.pl HASH:toybox ARRAY:toybox ARRAY:shelf
-- Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Parsing SOAP::Lite results
by Roboz (Novice) on Sep 28, 2012 at 13:44 UTC | |
by kcott (Archbishop) on Sep 28, 2012 at 15:13 UTC |