Through the magic of
List::MoreUtils:
use Modern::Perl qw/2015/;
use Data::Dump qw/dump/;
use List::MoreUtils qw/zip natatime/;
my $data1 = [
{
'NAME' => 'PAUL DY',
'DATE' => '2009-05-05',
'NUMBER' => '00001',
},
{
'NAME' => 'ANTHONY RD',
'DATE' => '2012-01-07',
'NUMBER' => '00003',
},
];
my $data2 = [
{
'CAR1' => '1',
'CAR2' => '2',
'CAR3' => '3',
},
{
'CAR1' => '1b',
'CAR2' => '2b',
'CAR3' => '3b',
},
];
my @all;
my $it = natatime 2, zip @$data1, @$data2;
while (my ($first, $second) = $it->()) {
push @all, {%$first, %$second};
}
say dump @all;
Output:
(
{
CAR1 => 1,
CAR2 => 2,
CAR3 => 3,
DATE => "2009-05-05",
NAME => "PAUL DY",
NUMBER => "00001",
},
{
CAR1 => "1b",
CAR2 => "2b",
CAR3 => "3b",
DATE => "2012-01-07",
NAME => "ANTHONY RD",
NUMBER => "00003",
},
)
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
My blog:
Imperial Deltronics