使用utf8时,Perl警告、严格模式和诊断错误不输出。

3
我已经在Windows 7上安装了Strawberry Perl 5.22,然后安装了包括Strawberry 5.14的Padre/Dwimperl。然后我卸载了5.22,并使用"D:\Dwimperl\perl\bin"中的"cpan SDL"安装了SDL。看起来它安装正确。
使用Padre(和/或命令行),我可以运行Perl脚本。但是,如果我引入一个错误("$r=0;"),则除非我注释掉"use utf8;",否则我将不会看到来自警告/严格/诊断的正常输出。
使用"use utf8;",我得到这个无用的错误:
BEGIN not safe after errors--compilation aborted at D:/Dwimperl/perl/lib/diagnos
tics.pm line 599.

没有它,我会得到更有帮助的错误提示:
Global symbol "$r" requires explicit package name at sdl2.pl line 12.
Execution of sdl2.pl aborted due to compilation errors (#1)
    (F) You've said "use strict" or "use strict vars", which indicates
    that all variables must either be lexically scoped (using "my" or "state"),

    declared beforehand using "our", or explicitly qualified to say
    which package the global variable is in (using "::").

Uncaught exception from user code:
        Global symbol "$r" requires explicit package name at sdl2.pl line 12.
Execution of sdl2.pl aborted due to compilation errors.
 at sdl2.pl line 15

这是我使用的脚本:

#! D:\Dwimperl\perl\bin\perl.exe
use warnings;
use strict;
use diagnostics;
use utf8;
binmode STDOUT, ':utf8';
$r = 0;
print "Hello World!\n";
exit 0;

有没有人能够提供建议,我如何保留有用的错误信息并使用utf8?


3
不,@Raju!他是故意忽略它以制造错误。原帖的问题在于当他使用utf8时错误没有得到正确报告。 - PerlDuck
1
我倾向于避免使用 use diagnostics。它实际上只是获取 use warnings 的输出并在 perldiag 中查找以打印出来,如果大多数编辑器和IDE实际上没有查找 warnings 模块的输出来突出显示问题,那将是很好的。 - tjd
@BlueGF,如果您发现这里提供的答案有帮助,请点赞和/或标记为已接受,以便其他有类似问题的用户受益。 - Wayne Booth
感谢@tjd的建议,我现在把"use diagnostics"注释掉了。如果遇到问题无法解决,我还是会去搜索互联网以获取更多信息。另一种选择是升级到更新的Perl版本。 - BlueGF
1个回答

3

1
它在5.16中被修复了。 - ikegami

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接