Hi all,
I try to find the average of colum with perl.
I find in forum that have the question http://www.daniweb.com/software-development/perl/threads/328723.
use 5.010;
my (@arr, %arr, $row);
while(<DATA>){
@arr=split(/\s+/, $_);
for (my $i=1; $i<=$#arr; $i++){
$arr{$i}+=$arr[$i];
}
$row++;
}
say ("total of column $_ is $arr{$_} and average is \t", ($arr{$_}/$row)) for (sort keys (%arr));
__DATA__
1 2 3 4 5
6 6 6 4 4
2 3 4 5 6
But I have problems with script. If the DATA have not a number it is erorr.
For example:
__data__
#########
1 2 3 4 5
6 6 6 4 4
2 3 4 5 6
Could you please show me what the problem and how to solve that.
Thank you very much.