level 5
Pulse_Z
楼主
perl子程序返回值不是看最后一次运算结果吗?就像这个例子
sub a
{
$fred+$barney;
}
$fred=3;
$barney=4;
$wilma=&a;
print $wilma;
子函数没有返回函数,但是本身返回了,运行结果是7
但是课后习题1
sub total
{
my $sub=0;
my @a=@_;
foreach $a(@a)
{
$sub=$sub+$a;
}
}
my @FRED = qw{1 3 5 7 9};
my $fred_total=total(@fred);
print "The total of \@fred is $fred_total.\n";
print "Enter some numbers on separate lines:";
my $user_total = total(<STDIN>);
print "The total of those numbers is $user_total.\n";
这样的程序就不会有结果显示
必须要在函数里面加上return $sub;才可以,这个子函数怎么就必须得加return了呢
2020年02月25日 16点02分
1
sub a
{
$fred+$barney;
}
$fred=3;
$barney=4;
$wilma=&a;
print $wilma;
子函数没有返回函数,但是本身返回了,运行结果是7
但是课后习题1
sub total
{
my $sub=0;
my @a=@_;
foreach $a(@a)
{
$sub=$sub+$a;
}
}
my @FRED = qw{1 3 5 7 9};
my $fred_total=total(@fred);
print "The total of \@fred is $fred_total.\n";
print "Enter some numbers on separate lines:";
my $user_total = total(<STDIN>);
print "The total of those numbers is $user_total.\n";
这样的程序就不会有结果显示
必须要在函数里面加上return $sub;才可以,这个子函数怎么就必须得加return了呢