in reply to Ways to group elements of an AoH

Put all the data you'll need in $allkeys and then just pull it all out with values.

my $allkeys; for ( @{ $allusers } ) { my $user = $_->{'user'}; if ( !exists $allkeys->{$user} ) { $allkeys->{$user} = { %{ $_ } }; } else { my $refAttributes = $allkeys->{$user}; $refAttributes->{'amount'} += $_->{'amount'}; $refAttributes->{'duration'} += $_->{'duration'}; } } my $finalArray = [ values %{ $allkeys } ];

Replies are listed 'Best First'.
Re^2: Ways to group elements of an AoH
by bradcathey (Prior) on Jan 04, 2009 at 04:41 UTC

    Sweet! So much cleaner. Thanks.

    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot