在 Perl 中,为什么当我尝试使用字符串 eval 时会出现语法错误?
为什么这不起作用?
eval "$response = $ua->request($r);"
print "$@";
给出:
syntax error at (eval 8) line 1, near "="
Why isn't this working?
eval "$response = $ua->request($r);"
print "$@";
gives:
syntax error at (eval 8) line 1, near "="
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一个更好的问题是为什么你首先要使用 eval ? 我怀疑您正在使用
LWP::UserAgent
,除非您实现自己的请求对象,否则“request”方法不太可能消失。因此,为什么不简单地使用:
?
An even better better question is why you are using eval in the first place? I suspect that you are using
LWP::UserAgent
and unless you implement your own request object, the 'request` method is unlikely do die.Thus, why not simply use:
?
它不起作用,因为双引号字符串会受到插值的影响,随着这些变量的扩展,这不会顺利进行。 并且您需要在 eval 外部添加分号,而不是在内部添加分号。 尝试像这样的单引号:
It isn't working because your double-quoted string is subject to interpolation, which is not going to go well, with those variables being expanded in place. And you need a semicolon outside your eval, not so much inside it. Try single quotes like so:
更好的问题是为什么使用字符串 eval,而不是块 eval?
A better question is why you are using a string eval, instead of a block eval?