#!/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(全部);” - 使用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.
答案 0 :(得分:7)
Unicode non-character 0xffff is illegal for interchange at ...
是编译时警告。
当您use warnings FATAL => all
时,您要求Perl将所有警告视为错误,因此它会成为编译时错误。