为什么错误消息不同?

时间:2017-06-23 21:29:14

标签: perl

我有两个程序:

#line 1 "DB::eval"
234asd

perl < tmp.pl
Bareword found where operator expected at DB::eval line 1, near "234asd"
    (Missing operator before asd?)
syntax error at DB::eval line 2, near "234asd
"
Execution of - aborted due to compilation errors.

和第二:

$str =  <<CODE;
#line 1 "DB::eval"
234asd
CODE
eval $str;
print $@;

perl < tmp.pl
Bareword found where operator expected at DB::eval line 1, near "#line 1 "DB::eval"
234asd"
    (Missing operator before asd?)
syntax error at DB::eval line 2, near "#line 1 "DB::eval"
234asd

"

为什么在第二种情况下我在错误消息中收到了额外的文字:#line 1 "DB::eval"?我不指望它。

同样在第二种情况下,我不期望额外的新线。我期待:

234asd
"

而不是:

234asd

"

1 个答案:

答案 0 :(得分:1)

我不会称这是一个错误,只是依赖于实现的行为。

第二个heredoc变体只包含更多上下文。 没有人保证heredoc的evals与直接脚本的行为相同。

p5p与我达成一致,Zefram没有把它称为bug,SawyerX拒绝了它。

相关问题