Assuming that the "Sample Data" in the OP was produced by a statement like
    print Dumper @$data;
then there are no arrayrefs in $data; rather, $data is a reference to an array containing elements that are hash references.

The
    foreach my $row (@$data) { ... }
loop of the OPed code iterates over the elements of the array referenced by $data; these elements are hash references. The $row scalar is aliased in turn to each hash reference and thus becomes a hash reference.

The
    if ($row->{ 'status' } eq "houses") { ... }
conditional block within the for-loop of the OPed code suggests you want to extract certain values from each referenced hash for which  $row->{ 'status' } eq "houses" is true, and your statement here suggests you want to then add the most recently extracted set of values back into all of the hash references of the array. This doesn't seem to make any sense, but it can be done:

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' }, ]; ;; my %last_houses; ;; foreach my $hr_row (@$data) { if ($hr_row->{ 'status' } eq 'houses') { @last_houses { qw(new_name new_ad1 new_City new_z_code) } = @{ $hr_row }{ qw(name Ad1 City zCode ) }; } } ;; foreach my $hr_row (@$data) { %$hr_row = (%$hr_row, %last_houses); } ;; print Dumper $data; " $VAR1 = [ { 'new_City' => 'BO', 'status' => 'Property', 'name' => 'John D', 'City' => 'NY', 'Ad1' => '20 SOUTH CENTRAL #B3', 'new_ad1' => '100 main St.', 'new_z_code' => '0007', 'zCode' => '0002', 'new_name' => 'Mary' }, { 'new_City' => 'BO', 'status' => 'Property', 'name' => 'John V', 'City' => 'NY', 'Ad1' => '15 SOUTH CENTRAL #B4', 'new_ad1' => '100 main St.', 'new_z_code' => '0007', 'zCode' => '0002', 'new_name' => 'Mary' }, { 'new_City' => 'BO', 'status' => 'houses', 'name' => 'Mary', 'City' => 'BO', 'Ad1' => '100 main St.', 'new_ad1' => '100 main St.', 'new_z_code' => '0007', 'zCode' => '0007', 'new_name' => 'Mary' } ];
Again, please consider if this makes any sense.

Update: Also, please consider what output you would want if your input were

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' }, { Ad1 => '13 Terminal St.', status => 'houses', City => 'LA' +, zCode => '6664', name => 'Larry' }, ];


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


In reply to Re^3: Add new data to array by AnomalousMonk
in thread Add new 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.