maikelnight has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks, i am new to perl...I have an array which Dumps to this:
$VAR1 = { '_shards' => { 'skipped' => 0, 'successful' => 5, 'total' => 5, 'failed' => 0 }, 'hits' => { 'hits' => [ { '_id' => 'AV6SrwuTv7sBjjRqMiW1', '_source' => { 'request' => '/inde +x.php', 'clientip' => '192. +168.1.1' }, '_type' => 'nginx', '_index' => 'nginx-2017.09.18', '_score' => '4.238926' }, { '_id' => 'AV6UL-DOv7sBjjRqMidb', '_source' => { 'clientip' => '192. +168.1.1', 'request' => '/' }, '_score' => '4.189655', '_type' => 'nginx', '_index' => 'nginx-2017.09.18' } ], 'total' => 2, 'max_score' => '4.238926' }, 'took' => 0, 'timed_out' => undef };
I try to get the key/values from '_source' but i dont know how. I can dump for example with: "print Dumper $_->{'hits'}{'hits'}->[0]->{'_source'};" and foreach, and get the pair from [0] and i can alter [0] to 1 and get the other pair.
foreach $_(@testarray) { print Dumper $_->{'hits'}{'hits'}->[0]->{'_source'}; }
But how can i loop through to get all the values? I tried to loop with foreach and a counter but it didnt work, it always gives [0] (indeed i might make a mistake). May i ask one to get me some help how to? Thanks a lot.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Looping trough Array Key/Value Pairs
by haukex (Archbishop) on Sep 25, 2017 at 10:55 UTC | |
by maikelnight (Sexton) on Sep 25, 2017 at 19:56 UTC | |
by AnomalousMonk (Archbishop) on Sep 25, 2017 at 23:38 UTC | |
|
Re: Looping trough Array Key/Value Pairs
by Discipulus (Canon) on Sep 25, 2017 at 11:28 UTC | |
|
Re: Looping trough Array Key/Value Pairs
by 1nickt (Canon) on Sep 25, 2017 at 13:35 UTC | |
|
Re: Looping trough Array Key/Value Pairs
by GrandFather (Saint) on Sep 25, 2017 at 21:51 UTC | |
|
Re: Looping trough Array Key/Value Pairs
by AnomalousMonk (Archbishop) on Sep 25, 2017 at 15:24 UTC | |
|
Re: Looping trough Array Key/Value Pairs
by thanos1983 (Parson) on Sep 25, 2017 at 11:57 UTC |