Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Seeking some noob wisdom with XML::Simple

by bobf (Monsignor)
on Feb 27, 2008 at 04:47 UTC ( [id://670483]=note: print w/replies, xml ) Need Help??


in reply to Seeking some noob wisdom with XML::Simple

foreach my $friendref ( @{ $VAR1->{ut_response}[0]{friend_list}{friend +} } ) { print "Hi $friendref->{user}\n"; }
meets your requirements, but it will benefit you in the long run to learn about references. See perlreftut, perldsc, and perlref for starters. Our Tutorials page has a section entitled Data Types and Variables, which will also help.

Update: Complex data structures can be tricky to wrap your head around at first. It might be easier to understand by breaking the solution into steps. Here is one way you could think about the goo in the foreach line, above:

@{ # the array referenced by: $VAR1-> # dereference $VAR {ut_response} # then get the value of the hash key 'ut_respo +nse' [0] # then get the 0th element of that array {friend_list} # then get the value of the hash key 'friend_l +ist' {friend} # then get the value of the hash key 'friend' }

Each one of those steps could be performed individually using temporary variables:

my $ut_aref = $VAR1->{ut_response}; my $href = $ut_aref->[0]; my $flist_href = $href->{friend_list}; my $f_aref = $flist_href->{friend}; foreach my $friendref ( @{ $f_aref } ) ...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-26 01:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found