Roboz has asked for the wisdom of the Perl Monks concerning the following question:
I have a question: How would I get data that is deep in the data structure when the higher level data is unknown? Yeah, I think an example is in order. I have XML similar to this:
<Things> <Thing> <Animal> <ThingName>Dog</ThingName> <ThingID>123</ThingID> </Animal> </Thing> <Thing> <Veg> <ThingName>Carrot</ThingName> <ThingID>42</ThingID> </Veg> </Thing> <Thing> <Mineral> <ThingName>Talc</ThingName> <ThingID>007</ThingID> </Mineral> </Thing> </Things>
BTW the formatting of this is completely out of my control. Anyway the SOAP::Lite result data structure looks like this:
$Var1 = \{ 'Thing' => [ { 'Animal' => { 'ThingName' => 'Dog', 'ThingID' => '123' } }, { 'Veg' => { 'ThingName' => 'Carrot', 'ThingID' => '42' } }, { 'Mineral' => { 'ThingName' => 'Talc', 'ThingID' => '007' } } ] };
And I'm trying to access the 'ThingName' without knowing whether it's 'Animal', 'Veg' or 'Mineral'. Is there a way to use a wildcard in the following code?
foreach my $e ( @{ $SOAPresult->{Thing} } ) { print "$e->{*wildcard here*}{ThingName}\n"; }
... or is there some other way to get there? In reality, there are many more than three different things, so trying each is not an option. Thanks for any help you great gurus can provide. I'm looking forward to when I can start answering instead of asking!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Getting deep data from SOAP::Lite Result
by kcott (Archbishop) on Oct 17, 2012 at 09:02 UTC | |
by Roboz (Novice) on Oct 17, 2012 at 09:20 UTC | |
|
Re: Getting deep data from SOAP::Lite Result
by Anonymous Monk on Oct 17, 2012 at 08:39 UTC | |
by Roboz (Novice) on Oct 17, 2012 at 11:24 UTC | |
by Anonymous Monk on Oct 17, 2012 at 23:54 UTC |