in reply to Looping trough Array Key/Value Pairs
See item 2 under Using References (or "Use Rule 1" in perlreftut), you can dereference any complex array references with @{...} and hash references with %{...}:
for my $hit ( @{ $VAR1->{hits}{hits} } ) { print "hit: '$hit->{_id}'\n"; for my $key ( keys %{ $hit->{_source} } ) { my $val = $hit->{_source}{$key}; print "key: '$key', val: '$val'\n"; } }
Outputs:
hit: 'AV6SrwuTv7sBjjRqMiW1' key: 'request', val: '/index.php' key: 'clientip', val: '192.168.1.1' hit: 'AV6UL-DOv7sBjjRqMidb' key: 'request', val: '/' key: 'clientip', val: '192.168.1.1'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Looping trough Array Key/Value Pairs
by maikelnight (Sexton) on Sep 25, 2017 at 19:56 UTC | |
by AnomalousMonk (Archbishop) on Sep 25, 2017 at 23:38 UTC |