perl中的$a和$b介绍
更新时间:2013年02月09日 23:47:22 作者:
有关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.
相关文章
Perl使用File::Basename获取文件扩展名的代码
本文为大家介绍的这个例子,实现了获取/home/topgkw中所有文件后缀,其中目录返回空值2013-02-02
perl之print,printf,sprintf使用案例详解
这篇文章主要介绍了perl之print,printf,sprintf使用案例详解,本篇文章通过简要的案例,讲解了该项技术的了解与使用,以下就是详细内容,需要的朋友可以参考下2021-09-09


最新评论