perl - 为什么错误消息不同?

标签 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

"

最佳答案

我不会将其称为错误,只是依赖于实现的行为。

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

p5p 同意我的看法,Zefram 没有将其称为错误,而 SawyerX 拒绝了它。

关于perl - 为什么错误消息不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44730203/

相关文章:

linux - 使用 konsole 通过 Perl 模拟终端

arrays - 无法解决的 Perl 错误?

perl - 无法 ssh :unable to establish master SSH connection: bad password or master process exited unexpectedly

windows - 在 Windows 上创建桌面链接的脚本?

Perl 和服务器-客户端套接字

perl - 如何从另一个 PL/Perl 函数调用 PL/Perl 函数?

perl - 在 Dancer2 中,保留模块的路由方法可以访问的类似服务对象的实例的首选方法是什么?

perl - 是否可以编写一个比 Perl 中的等效脚本更快的 shell 脚本?

perl - 如何强制 EXPR 而不是 GLOB 取消引用?

javascript - 在 Google Maps API 中显示多个 map 标记