Hi PerlMonks, Good Morning

Have a list of array hash, which printed below.

$logger->log( "sorted_data = ".Dumper(@sorted_data)); sorted_data = $VAR1 = { 'count_payment' => '', 'count_banking' => '31 (62.00)', 'name' => 'Parking Eye [LTD] One', }; $VAR2 = { 'count_payment' => '10 (144.00)', 'count_banking' => '', 'name' => 'Parking Eye [LTD] Two', }; $VAR3 = { 'count_payment' => '2 (80.42)', 'count_banking' => '', 'name' => 'Parking Eye [LTD] Three', }; $VAR4 = { 'count_payment' => '', 'count_banking' => '4 (982.00)', 'name' => 'Parking Eye [LTD] Two', };

Please, I need to merge two arrays with in the hash array based on the unique name condition, if ($a->{name} <=> $b->{name}). then move 'count_banking' => '4 (982.00)' value to the second where 'count_banking' => '' and remove the last array.

Expected output:

sorted_data = $VAR1 = { 'count_payment' => '', 'count_banking' => '31 (62.00)', 'name' => 'Parking Eye [LTD] One', }; $VAR2 = { 'count_payment' => '10 (144.00)', 'count_banking' => '4 (982.00)', 'name' => 'Parking Eye [LTD] Two', }; $VAR3 = { 'count_payment' => '2 (80.42)', 'count_banking' => '', 'name' => 'Parking Eye [LTD] Three', };

I tried like this below and stuck... please give me direction to achieve as expected output. Apologise if I showed here wrong approach.

foreach my $row ( sort { $a->{name} <=> $b->{name} } @sorted_data ) +{ #Move the values to second and remove the last one }

Thanks in advance.


In reply to How to merge two arrays within the hash of arrays based on unique name. by Sami_R

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.