node2:/root#cat sum.pl
open (my $fh,'<','aaa') or die$!;
while (<$fh>){
$count++;
print $count."
";
my $a=(split(/s+/,$_))[1];
print $a."
";
$b=$b+$a;
};
print "----------------------------
";
print $b."
";
print "----------------------------
";
node2:/root#cat aaa
a 13
b 23
c 3
d 9
e 10
node2:/root#perl sum.pl
1
13
2
23
3
3
4
9
5
10
----------------------------
58
----------------------------
node2:/root#cat sum.pl
open (my $fh,'<','aaa') or die$!;
while (<$fh>){
$count++;
print $count."
";
my $a=(split(/s+/,$_))[1];
print $a."
";
$b=$b+$a;
};
print "----------------------------
";
print $b."
";
print "----------------------------
";
print "平均值
";
print $b/$count."
";;
print "平均值
";
node2:/root#perl sum.pl
1
13
2
23
3
3
4
9
5
10
----------------------------
58
----------------------------
平均值
11.6
平均值