The $data array is updated. Print any part you want.
...# As before 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); }

OUTPUT:

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

In reply to Re^3: Add new rows and data to array. by BillKSmith
in thread Add new rows and data to array. by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.