Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Parsing SOAP::Lite results

by Anonymous Monk
on Sep 28, 2012 at 10:32 UTC ( #996163=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://996163]
help
Chatterbox?
talexb is happy to be on this site.

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (12)
As of 2018-07-19 13:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (408 votes). Check out past polls.

    Notices?