perl中的$a和$b介紹
更新時(shí)間:2013年02月09日 23:47:22 作者:
有關(guān)perl中的$a和$b,這兩個(gè)變量是為sort函數(shù)準(zhǔn)備的內(nèi)置變量,所以聲明時(shí)可以不加 my
即使打開了strict和warnings選項(xiàng)也無(wú)妨,下面代碼并無(wú)錯(cuò)誤和警告。
復(fù)制代碼 代碼如下:
#!/usr/bin/perl
use strict;
use warnings;
sub test {
$a = 1;
$b = 2;
print $a, "\n";
print $b, "\n";
}
test();
1;
下面是perl文檔中對(duì)這兩個(gè)變量的解釋:
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.
相關(guān)文章
Perl集群配置管理系統(tǒng)Rex簡(jiǎn)明手冊(cè)
這篇文章主要介紹了Perl集群配置管理系統(tǒng)Rex簡(jiǎn)明手冊(cè),自動(dòng)化運(yùn)維的一個(gè)管理工具,需要的朋友可以參考下2014-06-06
perl特殊符號(hào)及默認(rèn)的內(nèi)部變量
perl特殊符號(hào)及默認(rèn)的內(nèi)部變量,有需要的朋友不妨參考下2013-02-02
Perl使用File::Basename獲取文件擴(kuò)展名的代碼
本文為大家介紹的這個(gè)例子,實(shí)現(xiàn)了獲取/home/topgkw中所有文件后綴,其中目錄返回空值2013-02-02
perl之print,printf,sprintf使用案例詳解
這篇文章主要介紹了perl之print,printf,sprintf使用案例詳解,本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-09-09

