PERL特殊变量

Perl是个有个很多特殊变量的强大语言,这些特殊变量不需要程序员干涉就能够提供信息。

$.: 从当前输入文件中的去的行数。

$$: 当前进程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.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值