http://qs321.pair.com?node_id=996163


in reply to Parsing SOAP::Lite results

What am I doing wrong?

Basically, $getToysResults->{Toys}{Toy} is an arrayref and not a hash

#!/usr/bin/perl -- use strict; use warnings; my $getToysResults = { 'Toys' => bless( { 'Toy' => [ bless( { 'ToyLocations' => bless( { 'ToyLocation' => [ { 'toyQuantity' => '1', 'locationName' => 'toybox' }, { 'toyQuantity' => '4', 'locationName' => 'shelf' } ] }, 'ArrayOfToyLocation' ), 'color' => 'none', 'toyName' => 'Sorry', 'size' => 'medium' }, 'Board' ) ] }, 'ArrayOfToy' ) }; warn $getToysResults; warn $getToysResults->{Toys}; warn $getToysResults->{Toys}{Toy}; warn $getToysResults->{Toys}{Toy}{ToyLocations}; __END__ HASH(0x9b4fdc) at - line 27. ArrayOfToy=HASH(0x9b506c) at - line 28. ARRAY(0x9b50bc) at - line 29. Not a HASH reference at - line 30.

See diagnostics, References quick reference, ref, Data::Diver, SOAP::SOM#valueof(node)

use Data::Diver qw/ Dive /; my $toyArrRef = Dive $getToysResults, qw/ Toys Toy /; for my $toy ( @{ $toyArrRef } ){ my $arrToyLoc = Dive $toy, qw/ ToyLocations ToyLocation /; for my $hash ( @{ $arrToyLoc } ){ print "$$hash{locationName}\n"; } } __END__ toybox shelf

Replies are listed 'Best First'.
Re^2: Parsing SOAP::Lite results
by Roboz (Novice) on Sep 28, 2012 at 10:57 UTC

    The Data::Diver module looks interesting. Alas, I'm coding on an offline system so I'll have wait a bit before trying that. Thank you for the insight though.