Hi Monks, still learning to handle datastructures here, having a bit of trouble with some data that looks like this:
$VAR1 = { 'Addresses' => { 'ArrayOfAddressResponse' => { 'AddressRespo +nse' => [ + { + 'CountyName' => 'NEW YORK', + 'Street2' => {}, + 'LastLine' => 'NEW YORK NY 10025-4857', + + }, + { + 'CountyName' => 'NEW YORK', + 'Street2' => {}, + 'LastLine' => 'NEW YORK NY 10025-4858', + + }, + { + 'CountyName' => 'NEW YORK', + 'Street2' => {}, + 'LastLine' => 'NEW YORK NY 10025-4808', etc.
So what I think I see here is a hash containing an Array reference, and indeed if I print:
$content->{Addresses}{ArrayOfAddressResponse}{AddressResponse}
I get an "ARRAYx..." So I'm thinking I'd like to iterate through that list and do something with the values, so I do:
foreach my $response ( $content->{Addresses}{ArrayOfAddressResponse}{A +ddressResponse} ) {...
But when I do this and print $response inside the loop, it tells me it's an ARRAY. I can even dereference the data within the loop with like $response->[0]{Street}. But that doesn't seem to make sense. What am I mis-conceptualizing, here? I guess the crux of it is I can't figure out what to put inside the foreach parentheses to let me iterate through the list of hashes. Any input would be greatly appreciated!

In reply to Trouble dereferencing an array of hashes by rastoboy

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.