【问题】
写了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