Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How to merge two arrays within the hash of arrays based on unique name.

by tybalt89 (Monsignor)
on Jul 18, 2020 at 13:39 UTC ( [id://11119494]=note: print w/replies, xml ) Need Help??


in reply to How to merge two arrays within the hash of arrays based on unique name.

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11119433 use warnings; my @before = ( { 'count_payment' => '', 'count_banking' => '31 (62.00)', 'name' => 'Parking Eye [LTD] One', }, { 'count_payment' => '10 (144.00)', 'count_banking' => '', 'name' => 'Parking Eye [LTD] Two', }, { 'count_payment' => '2 (80.42)', 'count_banking' => '', 'name' => 'Parking Eye [LTD] Three', }, { 'count_payment' => '', 'count_banking' => '4 (982.00)', 'name' => 'Parking Eye [LTD] Two', } ); my @after; my %names; for my $record ( @before ) { my $hashref = $names{ $record->{name} } //= $after[ @after ] = {}; $hashref->{$_} ||= $record->{$_} for keys %$record; } use Data::Dump 'dd'; dd \@after;
  • Comment on Re: How to merge two arrays within the hash of arrays based on unique name.
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11119494]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (7)
As of 2024-04-24 10:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found