perl 基础学习_子过程
平时用C或C++编程的人,一看perl,应该感觉特别灵活吧,怎么这么多格式呀。在过程调用的时候,会涉及到C中所谓的形参。这个在perl中,是这样的
sub testPro {
my (@list1, @list2) = @_;
}
这是定义一个字过程,其中有@_, @_之意是,传递的当前参数的集合。当在子过程中调用传递的参数是,形式是: $_, $_
$_表示函数的第一个参数
$_表示函数的第二个参数 。
参考
@_ is the list of incoming parameters to a sub. So if you write a sub, you refer to the first parameter in it as $_, the second parameter as $_ 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 $_\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.
页:
[1]