Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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

by tybalt89 (Prior)
on Jul 18, 2020 at 13:39 UTC ( #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
Node Status?
node history
Node Type: note [id://11119494]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2020-10-24 09:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (242 votes). Check out past polls.

    Notices?