perl - 关于编译时错误的问题

标签 perl compilation

#!/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/

相关文章:

regex - Perl : Print all lines after match

json - 在 Perl Mojolicious 中渲染 JSON 时防止转义字符

javascript - angularjs 指令缓慢的 dom 操作

javascript - 即使路径正确,grunt-contrib-less 也找不到源文件

perl - Perl 中的递归搜索?

perl - linux中根据条件合并后续行

python - 如何在 Python 中将正则表达式子模式与命名组一起使用?

c++ - 在对象上调用静态成员函数——有没有办法让它变成编译器错误?

Java反编译->重新编译的过程,安全吗?

c++ - 使用 SSD 加快编译时间