子程序

子程序

由于所有的被调用的子程序都要返回值,因此使用特殊的返回值语法在大多数情况下是一种浪费。因此Larry 将之简化了。当Perl 遍历此子程序时,将会计算每一步的值。此子程序中最后计算的值将被返回。

 

 

例如,下面的子程序:
sub sum_of_fred_and_barney{
print “Hey, you called the sum_of_fred_and_barney suroutine!/n”;
$fred + $barney; #返回值
}
子程序中最后一个被计算的表达式为$fred + $barney,因此$fred 和$barney 的和将被返回。下面是一些调用代码:
$fred = 3;
$barney = 4;
$wilma = $sum_of_fred_and_barney; #$wilma 得到7
print “/$wilma is $wilma./n”;
$betty = 3 * &sum_of_fred_and_barney; #$betty 得到21
print “/n$betty is $betty./n”;
Perl 语言入门(第四版)
blei@163.com 55 / 201 9/21/2006
上述代码将得到下面的输出:
Hey, you call the sum_of_fred_and_barney subroutine!
$wilma is 7.
Hey, you call the sum_of_fred_and_barney subroutine!
$betty is 21.

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值