PERL特殊变量
2009-11-02 10:37
239 查看
Perl是个有个很多特殊变量的强大语言,这些特殊变量不需要程序员干涉就能够提供信息。
$.: 从当前输入文件中的去的行数。
$$: 当前进程ID
$^O: 当前操作系统
其他特殊变量反映了一些操作如何被执行。
$| 控制输出缓冲
$_ 默认输入和模式匹配空间。
如果从while循环的顶部读入一个文件句柄,或者运行一个foreach循环而且不知名一个循环变量,$_是为你准备的。
Shortens to:
@_ 函数的输入参数
。
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:
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
can have a detrimental performance effect if you're matching regular expressions against long incoming strings.
$.: 从当前输入文件中的去的行数。
$$: 当前进程ID
$^O: 当前操作系统
其他特殊变量反映了一些操作如何被执行。
$| 控制输出缓冲
$_ 默认输入和模式匹配空间。
如果从while循环的顶部读入一个文件句柄,或者运行一个foreach循环而且不知名一个循环变量,$_是为你准备的。
while ($line = <FH>) { if ($line =~ /Perl/) { print FHO $line; } print uc $line; }
Shortens to:
while (<FH>) { /Perl/ and print FHO ; print uc; }
@_ 函数的输入参数
。
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.
相关文章推荐
- Perl 特殊变量详解
- Perl 中的特殊变量 $&, $`,$' ,@_
- perl中的特殊内置变量(转)
- perl特殊变量(待续)
- perl内置特殊变量查询
- perl特殊变量
- Perl 特殊变量
- Perl内置特殊变量
- perl 特殊变量总结
- perl常用的内置特殊变量
- 举例说明PERL特殊变量
- perl 特殊变量(转)
- perl学习笔记九----特殊变量
- perl常用特殊变量列表
- Perl内置特殊变量
- Perl特殊变量 收藏
- perl特殊变量 转帖:http://blogold.chinaunix.net/u/8985/article.php? frmid=19739
- Perl中的特殊内置变量详细介绍
- Perl系统特殊变量
- Perl内置及特殊变量