kop*_*por 25
当之前的陈述未完成时,也可能发生这种情况.
use strict;
sub test;
test()
# some comment
my $x;
Run Code Online (Sandbox Code Playgroud)
perl现在抱怨以下错误消息:
my "
Global symbol "$x" requires explicit package name
Run Code Online (Sandbox Code Playgroud)
错误不在"我的"声明中,而是在缺少的分号(;)处test().
为了具体说明代码中的原因,您需要发布代码.
输出错误并且您的脚本已停止,因为您已获得use strict或衍生它.发生此错误是因为您的程序正在调用超出范围的变量.
您可能在子过程/函数中使用了我的或本地,但是尝试在另一个过程中或在函数调用之外使用它.
sub foo{
my $bar=0;
our ($soap) = 1;
}
foo();
print $bar , "\n"; # does not work w/ strict -- bar is only in the scope of the function, not globally defined
print $main::bar , "\n"; # will run, but won't be populated
print $soap , "\n"; # does not work w/ strict -- the package isn't defined
print $main::soap , "\n"; # will run and work as intended because of our
Run Code Online (Sandbox Code Playgroud)