用户登录
用户注册

分享至

perl中的$a和$b介绍

  • 作者: 非凡之享
  • 来源: 51数据库
  • 2020-08-09
有关perl中的$a和$b,这两个变量是为sort函数准备的内置变量,所以声明时可以不加 my

即使打开了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.

软件
前端设计
程序设计
Java相关