开发者

Question about compile-time-errors

开发者 https://www.devze.com 2023-02-13 10:34 出处:网络
#!/usr/bin/env perl use warnings; use 5.012; say \"no semicolon\" say \"World\"; say \"World\"; say \"World\";
#!/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

Why doesn't the second script tell me, that there was a compile-time-error?

When I can't - with a "use warnings FATAL => qw(all);" - catch the error with Try::Tiny or block-eval, can I conclude, that it is a compile-time-error?

#!/usr/bin/env perl
use warnings FATAL => qw(all);
use 5.012;
use Try::Tiny;

my $character;

try {
    $character = "\x{ffff}";
} catch {
    d开发者_JS百科ie "---------- caught error ----------\n";
};

say "something";

# Unicode non-character 0xffff is illegal for interchange at ./perl1.pl line 9.


Unicode non-character 0xffff is illegal for interchange at ... is a compile time warning.

When you use warnings FATAL => all, you are asking Perl to treat all warnings as errors, hence it becomes a compile time error.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号