in reply to Appending arrays into the rows of a 2 dimension array
Output for one of the keys:use strict; use warnings; use Data::Dumper; use List::Util qw(min max sum); my %hash; my @files = ('file1.txt','file2.txt'); for my $file (@files) { open(my $fh,"<",$file) or die "$file: $!"; while (my $line = <$fh>) { chomp $line; next unless $line; my @items = split(/\s+/,$line); my $key = shift @items; my $total = shift @items; $hash{$key}{'sum'} += $total; push(@{ $hash{$key}{'points'} }, @items ); } close($fh); } for my $key (keys %hash) { my $points = $hash{$key}{'points'}; $hash{$key}{'min'} = min(@$points); $hash{$key}{'max'} = max(@$points); $hash{$key}{'avg'} = $hash{$key}{'sum'} / @$points; # to print the points print join(' ',@$points) . "\n"; } print Dumper(\%hash);
'8' => { 'sum' => '29.489759' 'min' => '2.940214', 'max' => '3.083707', 'avg' => '2.9489759', 'points' => [ '3.011583', '2.943297', '2.940214', '2.955738', '2.968009', '3.083707', '2.958022', '2.957737', '2.982671', '2.990788' ], },
|
|---|