在Mastering Perl的章節之一,布賴恩·d FOY顯示了List::Util這個片段:這個Perl子程序中的use vars是什麼意思?
sub reduce(&@) {
my $code = shift;
no strict "refs";
return shift unless @_ > 1;
use vars qw($a $b);
my $caller = caller;
local(*{$caller . "::a"}) = \my $a;
local(*{$caller . "::b"}) = \my $b;
$a = shift;
foreach(@_) {
$b = $_;
$a = &{$code}();
}
$a;
}
我不明白什麼是use vars qw($a $b)
線的點。即使我評論它,我也會得到相同的輸出&警告。
您是否使用'use strict;使用警告;'在所有之前? – Ether 2010-02-14 16:58:40
一個詭辯 - 列出的代碼不是Bryan D Foy的 - 他引用了Graham Barr(List :: Util的創建者)的代碼。 – DVK 2010-02-14 17:11:47
是的,我做過。爲什麼? – Geo 2010-02-14 17:12:29