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!