Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Looping through an array

by tybalt89 (Monsignor)
on Sep 27, 2021 at 21:05 UTC ( [id://11137069]=note: print w/replies, xml ) Need Help??


in reply to Looping through an array

After converting your JSON to perl...

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11137065 use warnings; my $DATA = { required => [ { docs => [{ number => 1, sec => "123A" }], name => "Mary Lou" }, { docs => [{ number => 1, sec => 4567 }], name => "John De" }, { docs => [{ number => 1, sec => 8763 }], name => "Smith Doe" }, { docs => [{ number => 1, sec => "123B" }], name => "Joe De" }, ], }; for my $dta ( @{ $DATA->{required} } ) { my $sec = $dta->{docs}[0]{sec}; my $number = $dta->{docs}[0]{number}; my $name = $dta->{name}; print <<END; "sec": "$sec", "number": "$number" "name": "$name" END }

Outputs

"sec": "123A", "number": "1" "name": "Mary Lou" "sec": "4567", "number": "1" "name": "John De" "sec": "8763", "number": "1" "name": "Smith Doe" "sec": "123B", "number": "1" "name": "Joe De"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11137069]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-25 06:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found