用perl计算一系列数的和
要求:数据是有键盘输入的,个数不定。
#! /usr/bin/perl
sub total {
my $sum=0;
while (@_) {
$sum=$sum+pop @_;
}
return $sum;
}
print "Please input some numbers:\n";
$n=&total(<STDIN>);
print "the sum of these numbers is $n\n";
#! /usr/bin/perl
sub total {
my $sum=0;
while (@_) {
$sum=$sum+pop @_;
}
return $sum;
}
print "Please input some numbers:\n";
$n=&total(<STDIN>);
print "the sum of these numbers is $n\n";
none