gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 01:08:38 24 4
gpt4 key购买 nike

我有两个程序:

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com