PERL语言入门:第四章:子程序(函数):习题1:写一个程序, 求所有参数的和

#!/usr/bin/perl 
use warnings;
use strict;

sub sub_max{
	my $sum;
	foreach (@_){
		$sum += $_;
	}
	print "总和是: $sum \n";
	$sum;
}
&sub_max(1,2,3,4,5,6,7,8,9);
my @fred = qw{1 3 5 7 9};
my $fred_total = sub_max(@fred);
print "The total of \@fred is $fred_total.\n";
print "Enter some numbers on separate lines: \n";
#下面的输入, 每输入一个数, 要按一次回车
my $user_total = sub_max();
print "The total of those numbers if $user_total\n";

你可能感兴趣的:(perl基础)