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.


In reply to How do I iterate through this data set? by uG

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.