欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

perl中的$a和$b介绍

程序员文章站 2022-04-29 20:14:25
即使打开了strict和warnings选项也无妨,下面代码并无错误和警告。复制代码 代码如下:#!/usr/bin/perluse strict;use warnings...

即使打开了strict和warnings选项也无妨,下面代码并无错误和警告。

复制代码 代码如下:

#!/usr/bin/perl
use strict;
use warnings;
sub test {
    $a = 1;
    $b = 2;
    print $a, "\n";
    print $b, "\n";
}
test();
1;


下面是perl文档中对这两个变量的解释:

perldoc perlvar
$a
$b special package variables when using sort(), see "sort" in perlfunc. 
because of this specialness $a and $b don't need to be declared (using use vars, or our()) even when using the "strict 'vars'" pragma.  don't lexicalize them with "my $a" or "my $b" if you want to be able to use them in the sort() comparison block or function.