use strict; sub sum {my $x; $x += $_ for @_; $x } sub avg {sum(@_)/@_} undef $/; open(my $F, 'skaters.txt'); my @x = map{[split/,/]}grep{/\S/}split/\n+/,<$F>; for(@x){ @$_ = ($_->[0],avg(@{[sort{$a<=>$b}@{$_}[1..$#$_]]}[1..$#$_-2])) } @x = sort{$b->[1] <=> $a->[1]}@x; printf "%-5s %-20s %-20s\n",$_+1,@{$x[$_]} for(0..2); #### our $csvs = qr/(?:"(?:[^"]|"")*"|[^",])+/; sub csv_file_to_AoA { map{[csv($_)]}grep{/\S/}split/\n/,file_contents($_[0]) } sub csv { my @x = $_[0] =~ /(${csvs})(?:,|$)/g; for(@x){ /^"(.*?)"$/s ? $_ = $1 : undef; $_ =~ s/""/"/g; } @x } sub file_contents { local $/ = undef; open(my$F,$_[0])||die"cant open : $_[0]\n$!\n"; my $x = <$F> }