这是我到目前为止所做的,但代码只显示第1列的内容。我不确定如何计算列。我对编程很陌生,所以这可能是一个简单的问题。
my $filename = "Q5.txt";
open(my $fh, "<", $filename) or die "Could not open '$filename'\n";
while (my $line = <$fh>) {
$count++;
@line = $line;
for (@line) {
...
}
}
print $line[0];
答案 0 :(得分:2)
这样的事情应该适合你
use strict;
use warnings;
use autodie;
my $filename = 'Q5.txt';
my ($n, @totals);
open my $fh, '<', $filename;
while (<$fh>) {
my @fields = split;
$totals[$_] += $fields[$_] for 0 .. $#fields;
++$n;
}
$_ /= $n for @totals;
print "@totals\n";