in reply to Re^3: Counting elements in array of cases
in thread Counting elements in array of cases

Using a for instead of that grep

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11106779 use warnings; use List::Util qw( uniq ); my @AoH = ( { count => 1, origin => "AMG", targetL => "foisonnement" }, { count => 1, origin => "IDBR", targetL => "foisonnement" }, { count => 1, origin => "IWWF", targetL => "gonfler" }, { count => 1, origin => "IWWF", targetL => "due" }, { count => 1, origin => "IWWF", targetL => "due" }, ); my %seen; $_->{origin} = join ' ', uniq split ' ', $_->{origin} for my @AoHfinal + = map { if( my $prev = $seen{$_->{targetL}} ) { $prev->{count} += $_->{count}; $prev->{origin} .= ' ' . $_->{origin}; () # skip duplicate } else { $seen{$_->{targetL}} = { %$_ }; # copy hash so not destructive } } @AoH; use Data::Dump 'dd'; dd @AoHfinal;