最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】Perl运行出错:Global symbol xxx requires explicit package name at,Execution of xxx aborted due to compilation errors

Perl crifan 7616浏览 0评论

【问题】

写了perl代码:

#!/usr/bin/perl
use strict;
use warnings;

print "Hello, world";

$str = "I love Perl";
$str =~ m/Perl/;

去运行,结果出错:

E:\Dev_Root\Perl\reg_test>reg_test.pl
Global symbol "$str" requires explicit package name at E:\Dev_Root\Perl\reg_test\reg_test.pl line 7.
Global symbol "$str" requires explicit package name at E:\Dev_Root\Perl\reg_test\reg_test.pl line 8.
Execution of E:\Dev_Root\Perl\reg_test\reg_test.pl aborted due to compilation errors.

 

【解决过程】

1。参考:

perl里的global symbol requires explicit package name at xx

然后把use strict注释掉:

#!/usr/bin/perl
#use strict;
use warnings;

print "Hello, world";

$str = "I love Perl";
$str =~ m/Perl/;

然后就可以正常运行了:

E:\Dev_Root\Perl\reg_test>reg_test.pl
Hello, world

 

对应的原因,根据上面的解释是:

程序里用了use strict之后,就必须用our或者my声明变量。

【总结】

暂时懒得去深究了,等有空再深入了解背后的原因。

转载请注明:在路上 » 【已解决】Perl运行出错:Global symbol xxx requires explicit package name at,Execution of xxx aborted due to compilation errors

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.160 seconds, using 21.90MB memory