@testarray = { '_shards' => { 'skipped' => 0, 'successful' => 5, 'total' => 5, 'failed' => 0 }, ... };
And in that case what you mentioned dont work. I see you use $VAR1 (which works) but the goal would be to loop through an array with many elements....

A mental adjustment is needed here: initialized as shown,  @testarray is an array with a single element, an anonymous hash reference. If you can accommodate this properly in your code (or properly deal with an array with multiple elements), you will be on your way to your goal.

Remember: Data::Dumper and Data::Dump (my favorite) are your friends.

Update: Try this untested variation to haukex's posted code:

for my $hashref (@testarray) { for my $hit ( @{ $hashref->{hits}{hits} } ) { print "hit: '$hit->{_id}'\n"; for my $key ( keys %{ $hit->{_source} } ) { my $val = $hit->{_source}{$key}; print "key: '$key', val: '$val'\n"; } } }


Give a man a fish:  <%-{-{-{-<


In reply to Re^3: Looping trough Array Key/Value Pairs by AnomalousMonk
in thread Looping trough Array Key/Value Pairs by maikelnight

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.