perl 基础学习_子过程

平时用C或C++编程的人,一看perl,应该感觉特别灵活吧,怎么这么多格式呀。

在过程调用的时候,会涉及到C中所谓的形参。这个在perl中,是这样的

 sub testPro {
  my (@list1, @list2) = @_;
  }

 

 

这是定义一个字过程,其中有@_, @_之意是,传递的当前参数的集合。当在子过程中调用传递的参数是,形式是: $_[0], $_[1]

$_[0]表示函数的第一个参数 
$_[1]表示函数的第二个参数 。

参考

@_ is the list of incoming parameters to a sub. So if you write a sub, you refer to the first parameter in it as $_[0], the second parameter as $_[1] and so on. And you can refer to $#_ as the index number of the last parameter:
sub demo {
print "Called with ",$#_+1," params\n";
print "First param was $_[0]\n";


Note that the English module adds in the ability to refer to the special variables by other longer, but easier to remember, names such as @ARG for @_ and $PID for $$. But use English; can have a detrimental performance effect if you're matching regular expressions against long incoming strings.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值