|||
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 even prints assume you want to work on $_. Thus: 以数字为名的变量保存的是上一次匹配操作(/pattern/)中,第n个小括号中的原符号所匹配内容。 内插功能: $str = "aaa4zzz7bbb";$str =~ /(\d)z{3}(\d)/; print "$1\t$2n"; 输出结果是:4 7 |
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-7-28 00:09
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社