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 } )
...