rastoboy has asked for the wisdom of the Perl Monks concerning the following question:
So what I think I see here is a hash containing an Array reference, and indeed if I print:$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.
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:$content->{Addresses}{ArrayOfAddressResponse}{AddressResponse}
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!foreach my $response ( $content->{Addresses}{ArrayOfAddressResponse}{A +ddressResponse} ) {...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Trouble dereferencing an array of hashes
by bobf (Monsignor) on Nov 05, 2009 at 03:59 UTC | |
by rastoboy (Monk) on Nov 05, 2009 at 07:57 UTC | |
|
Re: Trouble dereferencing an array of hashes
by colwellj (Monk) on Nov 05, 2009 at 03:47 UTC | |
|
Re: Trouble dereferencing an array of hashes
by Anonymous Monk on Nov 05, 2009 at 03:32 UTC |