The idea is strange, but the data in status => "Houses" needs to be in status => "Main" only and it isn't formatted like that in the database, so by using the magic of Perl, I was sure that it would be possible. This is what could work, unless it could be even more simplified.

#!/usr/bin/perl use strict; use warnings; use DBI; use Data::Dumper; my $data =[ { Ad1 => '20 SOUTH CENTRAL #B3', status => 'Main', 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 Due' }, { Ad1 => '5540 Chelsea Avenue', status => 'Cabin', City => 'NE +', zCode => '4562', name => 'Carly Simon' }, ]; my %last_houses; foreach my $hr_row (@$data) { if ($hr_row->{ 'status' } eq 'Houses') { @last_houses { qw(new_name new_aA1 new_City new_zCode) } = @{ $hr_row }{ qw(name Ad1 City zCode ) }; } } foreach my $hr_row (@$data) { if ($hr_row->{ 'status' } eq 'Main') { %$hr_row = (%$hr_row, %last_houses); } } print Dumper $data; =code $VAR1 = [ { 'new_City' => 'BO', 'status' => 'Main', 'name' => 'John D', 'City' => 'NY', 'new_aA1' => '100 main St.', 'new_zCode' => '0007', 'Ad1' => '20 SOUTH CENTRAL #B3', 'zCode' => '0002', 'new_name' => 'Mary Due' }, { 'status' => 'Property', 'name' => 'John V', 'Ad1' => '15 SOUTH CENTRAL #B4', 'City' => 'NY', 'zCode' => '0002' }, { 'status' => 'Houses', 'name' => 'Mary Due', 'Ad1' => '100 main St.', 'City' => 'BO', 'zCode' => '0007' }, { 'status' => 'Cabin', 'name' => 'Carly Simon', 'Ad1' => '5540 Chelsea Avenue', 'City' => 'NE', 'zCode' => '4562' } ]; =cut


Thank you!

In reply to Re^4: Add new data to array by Anonymous Monk
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.