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/

相关文章:

mysql - 无法从 perl 脚本运行 MySQL 存储过程

xml - 如何在 perl 中进行验证

regex - grep 与 Perl。我应该修改它来工作,还是应该用 Perl 代码替换它?

perl - 如何在 nginx 错误日志中获取 perl 脚本错误(Nginx with FCGIwrap)

perl - 如何使用固定连接条件建立 DBIx::Class 关系?

python - 长度为 k 的非重叠子串的随机采样

perl - Digest::SHA 相对于 Digest::SHA1 有哪些优点?

perl - 在 Perl 中读取数据 block

perl - 使用perl替换文件第一行的问题

arrays - 使用另一个数组循环遍历一个数组而不加入它们