|
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 ($.) through the current process ID ($$) and the operating system ($^O). Other special variables effect how certain operations are performed ($| controlling output buffering / flushing, for example), or are fundamental in the operation of certain facilities - no more so than $_ and @_. ------------------------------------------- 1.@_含义 1)是perl中默认的数组变量 2)是sub子函数中的默认参数列表. 例如: 再例如,有下面一段代码: 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: 2.$_含义 1)$_为默认列表变量。在一个命令没有任何参数的时候,表示它从默认变量里读取。 --------------------------- Then any regular expression matches, chops (and lcs and many more) without a parameter, and evenprints assume you want to work on $_. Thus: 以数字为名的变量保存的是上一次匹配操作(/pattern/)中,第n个小括号中的原符号所匹配内容。 内插功能: $str = "aaa4zzz7bbb";$str =~ /(\d)z{3}(\d)/; print "$1\t$2\n"; 输出结果是:4 7 |
perl中@_,$_和$1,$2,...及其类似变量的含义
最新推荐文章于 2026-02-13 05:39:58 发布
本文深入解析Perl中的特殊变量@_和$_的功能与用法。@_作为子函数默认参数列表及默认数组变量的角色,在处理传入参数时极为方便。而$_则作为默认列表变量和模式匹配空间,在进行字符串处理时提供了简化语法。
193

被折叠的 条评论
为什么被折叠?



