Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Add new data to array

by AnomalousMonk (Bishop)
on Mar 13, 2020 at 23:27 UTC ( #11114240=note: print w/replies, xml ) Need Help??


in reply to Add new data to array

Your expected output is not consistent with your example input (which you don't show, but which we can make a good guess at) and the operations you show, but here's a guess at something you might find useful.

c:\@Work\Perl\monks>perl -wMstrict -MData::Dumper -le "my $data = [ { Ad1 => '20 SOUTH CENTRAL #B3', status => 'Property', City => 'NY +', zCode => '0002', name => 'John D' }, { Ad1 => '15 SOUTH CENTRAL #B4', status => 'Property', City => 'NY +', zCode => '0002', name => 'John V' }, { Ad1 => '100 main St.', status => 'houses', City => 'BO +', zCode => '0007', name => 'Mary' }, ]; ;; foreach my $hr_row (@$data) { if ($hr_row->{ 'status' } eq 'houses') { my $name = $hr_row->{ 'name' } || ''; my $ad1 = $hr_row->{ 'Ad1' } || ''; my $town = $hr_row->{ 'City' } || ''; my $zcode = $hr_row->{ 'zCode' } || ''; ;; @{ $hr_row }{ qw(new_name new_ad1 new_City new_z_code) } = ( $name, $ad1, $town, $zcode ); } } ;; print Dumper $data; " $VAR1 = [ { 'status' => 'Property', 'name' => 'John D', 'Ad1' => '20 SOUTH CENTRAL #B3', 'City' => 'NY', 'zCode' => '0002' }, { 'status' => 'Property', 'name' => 'John V', 'Ad1' => '15 SOUTH CENTRAL #B4', 'City' => 'NY', 'zCode' => '0002' }, { 'new_City' => 'BO', 'status' => 'houses', 'new_ad1' => '100 main St.', 'name' => 'Mary', 'Ad1' => '100 main St.', 'City' => 'BO', 'new_z_code' => '0007', 'new_name' => 'Mary', 'zCode' => '0007' } ];
Please see Short, Self-Contained, Correct Example, How do I post a question effectively? and How (Not) To Ask A Question (and maybe I know what I mean. Why don't you?).


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^2: Add new data to array
by Anonymous Monk on Mar 14, 2020 at 02:22 UTC
    Its almost like that, I just need all the new data to be in all arrays as well:
    { 'status' => 'Property', 'name' => 'John D', 'Ad1' => '20 SOUTH CENTRAL #B3', 'City' => 'NY', 'zCode' => '0002', 'new_City' => 'BO', 'new_ad1' => '100 main St.', 'new_z_code' => '0007', 'new_name' => 'Mary', }, { 'status' => 'Property', 'name' => 'John V', 'Ad1' => '15 SOUTH CENTRAL #B4', 'City' => 'NY', 'zCode' => '0002', 'new_City' => 'BO', 'new_ad1' => '100 main St.', 'new_z_code' => '0007', 'new_name' => 'Mary' }, { 'new_City' => 'BO', 'status' => 'houses', 'new_ad1' => '100 main St.', 'name' => 'Mary', 'Ad1' => '100 main St.', 'City' => 'BO', 'new_z_code' => '0007', 'new_name' => 'Mary', 'zCode' => '0007' }

    Thanks!!!!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2020-05-25 02:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (143 votes). Check out past polls.

    Notices?