Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Trouble Getting Deep Into a Hash from XML::Parser

by inblosam (Monk)
on Sep 02, 2006 at 12:37 UTC ( [id://570865]=note: print w/replies, xml ) Need Help??


in reply to Re: Trouble Getting Deep Into a Hash from XML::Parser
in thread Trouble Getting Deep Into a Hash from XML::Simple

One more associated problem, how do I know how many to expect when I am running through adding each of these to an array of hashes? There's got to be a better way to handle it. The code below works, but the XML has a different number of results each time for the "moreSpecific" tag. Any suggestions??
my $moreListCnt = 2; my $cnt = 0; my @morelist; for (;$cnt<$moreListCnt;$cnt++) { $morelist[$cnt]{'more'} = $content->{'soapenv:Body'}{'getKeywordVa +riationsResponse'}{'getKeywordVariationsReturn'}{'moreSpecific'}[$cnt +]->{'text'}; $morelist[$cnt]{'comp'} = $content->{'soapenv:Body'}{'getKeywordVa +riationsResponse'}{'getKeywordVariationsReturn'}{'moreSpecific'}[$cnt +]->{'advertiserCompetitionScale'}; $morelist[$cnt]{'pop'} = $content->{'soapenv:Body'}{'getKeywordVar +iationsResponse'}{'getKeywordVariationsReturn'}{'moreSpecific'}[$cnt] +->{'searchVolumeScale'}; }
Thanks!!


Michael

Replies are listed 'Best First'.
Re^3: Trouble Getting Deep Into a Hash from XML::Parser
by runrig (Abbot) on Sep 02, 2006 at 17:36 UTC
    First, I would use ForceArray on the moreSpecific tag (if there is only one 'moreSpecific' node, it will not make an array), and you don't need the count to access all of the subnodes.
    my $morelist = $content->{'soapenv:Body'}{'getKeywordVariationsRespons +e'}{'getKeywordVariationsReturn'}{'moreSpecific'}; for my $more (@$morelist) { print "$more->{text}\n"; print "$more->{advertiserCompetitionScale}\n"; print "$more->{searchVolumeScale}\n"; $more->{more} = $more->{text}; $more->{comp} = $more->{advertiserCompetitionScale}; $more->{pop} = $more->{searchVolumeScale}; }
    Update: fixed, updated example.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://570865]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-20 09:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found