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.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |