in reply to Add new rows and data to array.
use strict; use warnings; use Data::Dumper; my $data =[ ... # Ref OP ]; my @extras = grep {$_->{status} eq 'Extra'} @$data; my @mains = grep {$_->{status} eq 'Main' } @$data; MAIN: foreach my $main (@mains) { EXTRA: foreach my $extra (@extras) { next EXTRA if $main->{ID} ne $extra->{ID}; @{$main}{qw/new_name new_ad1 new_city new_z_code/} = @{$extra}{qw/name Ad1 City zCode/}; print Dumper($main); next MAIN; } }
OUTPUT:
$VAR1 = { 'ID' => '2222', 'City' => 'NY', 'zCode' => '0002', 'Ad1' => '20 North Central St.', 'name' => 'John D', 'state' => 'TO', 'new_z_code' => '0007', 'new_ad1' => '100 main St.', 'status' => 'Main', 'new_city' => 'BO', 'new_name' => 'Tony Star' }; $VAR1 = { 'zCode' => '2334', 'name' => 'Charles D', 'Ad1' => '12th Street', 'ID' => '1111', 'City' => 'NM', 'new_name' => 'Marie Doe', 'status' => 'Main', 'new_city' => 'MA', 'new_z_code' => '9857', 'state' => 'CA', 'new_ad1' => '44 Dell St' };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Add new rows and data to array.
by Anonymous Monk on Mar 19, 2020 at 21:35 UTC | |
by BillKSmith (Monsignor) on Mar 19, 2020 at 22:21 UTC | |
by Anonymous Monk on Mar 19, 2020 at 22:36 UTC | |
by BillKSmith (Monsignor) on Mar 20, 2020 at 00:16 UTC | |
by Anonymous Monk on Mar 21, 2020 at 02:44 UTC | |
by BillKSmith (Monsignor) on Mar 21, 2020 at 14:38 UTC |