perl 中的vars是perl中的一個pragma(預(yù)編譯指示符),專門用來預(yù)定義全局變量,這些預(yù)定義后的全局變量在qw()列表中,在整個引用perl文件中皆可使用,即便使用use strict也不會報錯:
復(fù)制代碼 代碼如下:
use strict ;
$str = "hello world!\n" ;
報錯信息:Global symbol "$str" requires explicit package name at ~vars.pl line 3.
Execution of ~vars.pl aborted due to complication errors.
引用use vars后執(zhí)行結(jié)果:
復(fù)制代碼 代碼如下:
use strict ;
use vars qw($str) ;
$str = "hello world!\n" ;
print $str ;
Output :
hello world!