Hello kfriman,
Is this something that you are looking for?
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @AoA = ( [ "1", "PC BOX", "20.0" ], [ "1", "PC Spare", "32.0" ], [ "1", "PC Spare", "2.0" ], [ "1", "PC Spare", "5.2" ], [ "1", "PE Ak", "100.0" ], ); sub process_dublications { my $j = 0; my @AoA_local; my ($hashRefAoH) = @_; # print the whole thing with indices foreach my $key ( keys %{$hashRefAoH} ) { my $total; my $element = 0; foreach my $i ( 0 .. $#{ $hashRefAoH->{$key} } ) { $total += $hashRefAoH->{$key}[$i]; $element++; } push @{$AoA_local[$j++]}, $element, $key, $total; } return \@AoA_local; } my %HoA; # print the whole thing one at a time for my $i ( 0 .. $#AoA ) { next unless push @{ $HoA{$AoA[$i][1]} }, $AoA[$i][2]; } my $AoA_ref = process_dublications(\%HoA); my @sorted = sort { $a->[0] <=> $b->[0] || $a->[2] <=> $b->[2] } @{$Ao +A_ref}; print Dumper \@sorted; __END__ $VAR1 = [ [ 1, 'PC BOX', 20 ], [ 1, 'PE Ak', 100 ], [ 3, 'PC Spare', '39.2' ] ];
If you really want to keep the comma on the float you need to convert the comma to dot and after the calculation vise versa.
Hope this helps.
In reply to Re: Grouping of 2D arrays
by thanos1983
in thread Grouping of 2D arrays
by kfriman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |