Perl's a great language for special variables - variables that are set up without the programmer having to intervene and providing information ranging from the number of lines read from the current input file (
-------------------------------------------
1.@_含义
1)是perl中默认的数组变量
比如说你想移除数组中的一个元素赋值给一个变
方法2:你没有定义任何数组
my $value=shift @_; 和上例等效
这里perl会隐式的选择@_
例如:
sub funct($$) {
($param1,$param2) = @_;
#Statement
}
再例如,有下面一段代码:
my max_number = &max(1,2); print "1 and 2 ,the max number ismax_number\n";
sub max{
my (
........此处省略求max运算
}
在子函数中直接shift; 就可以从@_的前端弹出一个元素.
shift;
等于
shift @_;
-------------------------
@_ 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
2.$_含义
1)
2)默认模式匹配空间(pattern matching space)
s/.../.../;
等于
$_ =~ s/.../.../;
---------------------------
Then any regular expression matches, chops (and lcs and many more) without a parameter,and even prints assume you want to work on
if (
}
Shortens to:
while (<FH>) {
/Perl/ and
print FHO ;
print uc;
}
3.
以数字为名的变量保存的是上一次匹配操作(/pattern/)中,第n个小括号中的原符号所匹配内容。
内插功能:
print "
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。