Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

G'day Roboz,

Firstly, the data structure you present is invalid. In the code below, I've added a closing brace to 'Mineral' => { .... Also, you show $Var1 as being a reference to a hashref: I don't know if that's correct or another typo - the following code assumes it is correct.

This code shows how you might go about achieving what you're after. I'll leave you to make adjustments for whatever typos may exist.

#!/usr/bin/env perl use strict; use warnings; my $SOAPresult = \{ 'Thing' => [ { 'Animal' => { 'ThingName' => 'Dog', 'ThingID' => '123' } }, { 'Veg' => { 'ThingName' => 'Carrot', 'ThingID' => '42' } }, { 'Mineral' => { 'ThingName' => 'Talc', 'ThingID' => '007' } } ] }; my $SOAPresult_deref = $$SOAPresult; my @types = qw{Animal Veg Mineral}; for my $type (@types) { foreach my $e ( @{ $SOAPresult_deref->{Thing} } ) { next unless exists $e->{$type}; print "Wildcard = $type\n"; print "$e->{$type}{ThingName}\n"; } }

Output:

$ pm_ref_var_access.pl Wildcard = Animal Dog Wildcard = Veg Carrot Wildcard = Mineral Talc

-- Ken


In reply to Re: Getting deep data from SOAP::Lite Result by kcott
in thread 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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2024-04-24 21:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found