#!/usr/bin/env perl
use warnings;
use 5.012;
say "no semicolon"
say "World";
say "World";
say "World";
say "World";
say "World";
# syntax error at ./perl1.pl line 7, near "say"
# Execution of ./perl1.pl aborted due to compilation errors.
.
#!/usr/bin/env perl
use warnings;
use 5.012;
my $character = "\x{ffff}";
say "Hello";
say "Hello";
say "Hello";
say "Hello";
say "Hello";
# Unicode non-character 0xffff is illegal for interchange at ./perl1.pl line 5.
# Hello
# Hello
# Hello
# Hello
# Hello
为什么第二个脚本没有告诉我存在编译时错误?
当我不能时 - 使用“使用警告 FATAL => qw(all);” - 使用 Try::Tiny 或 block-eval 捕获错误,我可以得出结论,这是一个编译时错误吗?
#!/usr/bin/env perl
use warnings FATAL => qw(all);
use 5.012;
use Try::Tiny;
my $character;
try {
$character = "\x{ffff}";
} catch {
die "---------- caught error ----------\n";
};
say "something";
# Unicode non-character 0xffff is illegal for interchange at ./perl1.pl line 9.
最佳答案
Unicode 非字符 0xffff is illegal for interchange at ...
是编译时警告。
当您使用警告 FATAL => all
时,您要求 Perl 将所有警告视为错误,因此它变成了编译时错误。
关于perl - 关于编译时错误的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5129420/