uG has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to iterate through what I thought was an array of lists. Here is the first piece of the dataset:
$VAR1 = { 'timestamp' => '2011-05-21T18:21:40.588Z', 'version' => '1.10.0', 'ack' => 'Success', 'paginationOutput' => { 'totalPages' => '59', 'pageNumber' => '1', 'entriesPerPage' => '100', 'totalEntries' => '5812' }, 'searchResult' => { 'count' => '100', 'item' => [ { 'primaryCategory' => { 'category +Id' => '63850', 'category +Name' => 'Mixed Items & Lots' }, 'distance' => { 'unit' => 'mi', 'content' => '18 +75.0' }, 'sellingStatus' => { 'convertedC +urrentPrice' => { + 'currencyId' => 'USD', + 'content' => '1.0' + }, 'currentPri +ce' => { + 'currencyId' => 'USD', + 'content' => '1.0' + }, 'sellingSta +te' => 'Active', 'timeLeft' +=> 'P3DT18H28M2S', 'bidCount' +=> '0' },
You can also view the full thing at ugexe.com/file.txt but it repeats itself a lot (and i've included the relevant part). Here is how I am attempting to iterate and grab the values:
foreach my $n ( $hash->{'searchResult'}->{'item'} ) { my $item = { item_link => $n->{'viewItemURL'}, item_number => $n->{'itemId'}, title => $n->{'title'}, subtitle => $n->{'subtitle'}, current_bid => $n->{'currentPrice'}->{'content'}, }; }
My error comes when I try to create the anonymous list using $n->{'viewItemURL'} (or whatever viewItemUrl may be). It tells me $n is not a hash reference. So I am a little confused on how I am suppose to get the values from this dataset.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How do I iterate through this data set?
by Corion (Patriarch) on May 21, 2011 at 19:18 UTC | |
Re: How do I iterate through this data set?
by 7stud (Deacon) on May 21, 2011 at 20:28 UTC | |
Re: How do I iterate through this data set?
by planetscape (Chancellor) on May 22, 2011 at 13:58 UTC | |
Re: How do I iterate through this data set?
by sundialsvc4 (Abbot) on May 23, 2011 at 12:19 UTC |
Back to
Seekers of Perl Wisdom