The numbers in the file are: 1 1 1
2 2 2
3 3 3
After I run my script I keep on getting the sum of the columns and not the average.
#!/usr/bin/perl
$A = 0;
$B = 0;
$C = 0;
$rows = 0;
open (file, "sample.txt") || die "couldn't open the file!";
while ($info = <file>) {
$info=~m/^(\d)\s(\d)\s(\d)/;
$A += $1;
$B += $2;
$C += $3;
$rows=$rows+1;
}
Close(file);
print "\n= ", $A;
print "\n= ", $B;
print "\n= ", $C;
$A /= $rows;
$B /= $rows;
$C /= $rows;
I changed the order of the code but now I am getting 9 values instead of 3. I only have 3 columns so can anyone tell me why I am receiving 9 values?
2 2 2
3 3 3
After I run my script I keep on getting the sum of the columns and not the average.
#!/usr/bin/perl
$A = 0;
$B = 0;
$C = 0;
$rows = 0;
open (file, "sample.txt") || die "couldn't open the file!";
while ($info = <file>) {
$info=~m/^(\d)\s(\d)\s(\d)/;
$A += $1;
$B += $2;
$C += $3;
$rows=$rows+1;
}
Close(file);
print "\n= ", $A;
print "\n= ", $B;
print "\n= ", $C;
$A /= $rows;
$B /= $rows;
$C /= $rows;
I changed the order of the code but now I am getting 9 values instead of 3. I only have 3 columns so can anyone tell me why I am receiving 9 values?