Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^4: Add new rows and data to array.

by Anonymous Monk
on Mar 19, 2020 at 22:36 UTC ( [id://11114492]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Add new rows and data to array.
in thread Add new rows and data to array.

Noticed that I still need to new rows, but empty because there is no status = extra related to that one :

$VAR9 = { 'new_City' => '', <<<<<<< 'ID' => '8888', 'status' => 'Main', 'name' => 'AKAKAK', 'City' => 'AA', 'state' => 'PP', 'new_ad1' => '', <<<<<<< 'Ad1' => '1AAAA', 'new_z_code' => '', <<<<<< 'new_name' => '', <<<<<< 'zCode' => 'TTTT' };

Replies are listed 'Best First'.
Re^5: Add new rows and data to array.
by BillKSmith (Monsignor) on Mar 20, 2020 at 00:16 UTC
    I think that you now want to add the four new keys (with the value of each initialized to the null string) to every hash which has a status of 'Main'. Update the values if they are available in an 'extra' hash.
    ... # As before my @extras = grep {$_->{status} eq 'Extra'} @$data; my @mains = grep {$_->{status} eq 'Main' } @$data; MAIN: foreach my $main (@mains) { @{$main}{qw/new_name new_ad1 new_city new_z_code/} = ('', '', '', ''); 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/}; last EXTRA; } print Dumper($main); }

    OUTPUT:

    $VAR1 = { 'City' => 'NY', 'new_city' => 'BO', 'new_ad1' => '100 main St.', 'Ad1' => '20 North Central St.', 'new_name' => 'Tony Star', 'zCode' => '0002', 'state' => 'TO', 'status' => 'Main', 'new_z_code' => '0007', 'name' => 'John D', 'ID' => '2222' }; $VAR1 = { 'City' => 'NM', 'new_city' => 'MA', 'new_ad1' => '44 Dell St', 'Ad1' => '12th Street', 'state' => 'CA', 'zCode' => '2334', 'status' => 'Main', 'new_name' => 'Marie Doe', 'new_z_code' => '9857', 'name' => 'Charles D', 'ID' => '1111' }; $VAR1 = { 'new_ad1' => '', 'City' => 'AA', 'new_city' => '', 'Ad1' => '1AAAA', 'new_name' => '', 'status' => 'Main', 'state' => 'PP', 'zCode' => 'TTTT', 'name' => 'AKAKAK', 'ID' => '8888', 'new_z_code' => '' };
    Bill

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-24 13:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found