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!


In reply to Getting deep data from SOAP::Lite Result by Roboz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.