in reply to Re: Parsing SOAP::Lite results
in thread Parsing SOAP::Lite results
Tried your suggestion and received a 'Not an ARRAY reference' error on the for my $location_array_hash_ref (@$location_array_ref) { line...
Yeah, the naming convention is due to an XML schema I have no control over.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Parsing SOAP::Lite results
by kcott (Archbishop) on Sep 28, 2012 at 12:05 UTC | |
I tested that code before posting. I changed $VAR1 to my $getToysResults but otherwise left the Dumper output unchanged. Here's the script (pm_parse_soap_hash.pl) in its entirety:
Here's the output:
Try running that script. If it works, then maybe the data you posted was incorrect (typo, cut-and-paste error, etc.) or perhaps you used my code differently. Try adding print Dumper $getToysResults; just before the outer foreach in your code and see if it produces the same output as you originally posted. If it doesn't work, please post full output along with your Perl version and OS: as it stands, I can't see anything there that wouldn't work on any version of Perl 5. -- Ken | [reply] [d/l] [select] |
by Roboz (Novice) on Sep 28, 2012 at 12:52 UTC | |
I see what's causing my issue with the 'Not an ARRAY ref' error. When there is only one location it's not an array.
Still stuck on what to do in this case. Would this be where introspection comes in? pseudo:(if HASH, then ... %$location) elsif ARRAY, then ... @$location) ? Thanks to all who are helping me learn this! | [reply] [d/l] [select] |
by kcott (Archbishop) on Sep 28, 2012 at 13:21 UTC | |
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.
Output:
-- Ken | [reply] [d/l] [select] |
by Roboz (Novice) on Sep 28, 2012 at 13:44 UTC | |
by kcott (Archbishop) on Sep 28, 2012 at 15:13 UTC | |
by Anonymous Monk on Sep 28, 2012 at 12:57 UTC | |
Yes, ref is ref | [reply] |
Re^3: Parsing SOAP::Lite results
by 2teez (Vicar) on Sep 28, 2012 at 12:16 UTC | |
Kcott's code works perfectly.
If you tell me, I'll forget. If you show me, I'll remember. if you involve me, I'll understand. --- Author unknown to me | [reply] [d/l] |