Here is a way to store all the information in a hash and deal with those new lines:
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);
Output for one of the keys:
'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' ], },

In reply to Re: Appending arrays into the rows of a 2 dimension array by tangent
in thread Appending arrays into the rows of a 2 dimension array by SoftwareGoddess

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.