如何将变量传递到 Perl 脚本中的 URL 中?
如何将变量传递到 Perl 脚本中的 URL 中? 我正在尝试将数组中的变量传递给 url。由于某种原因它不起作用。我不确定我做错了什么。代码大致如下:
@coins = qw(Quarter Dime Nickel);
foreach (@coins) {
my $req = HTTP::Request->new(POST =>'https://url/$coins.com');
}
这不起作用,因为 $coins
不会分别切换到 Quarter、Dime、Nickel。
我做错了什么?
How do I pass a variable into a URL in a Perl script?
I am trying to pass the variables in an array to url. For some reason it is not working. I am not sure what I am doing wrong. The code roughly looks like this:
@coins = qw(Quarter Dime Nickel);
foreach (@coins) {
my $req = HTTP::Request->new(POST =>'https://url/$coins.com');
}
This does not work as $coins
does not switch to Quarter,Dime,Nickel respectively.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,变量不会插入单引号字符串中:
其次,任何地方都没有定义变量
$coins
:另外,请确保使用 严格 和警告。
您还应该投入一些时间来正确学习 Perl。
First, variables do not interpolate in single quoted strings:
Second, there is no variable
$coins
defined anywhere:Also, make sure to use strict and warnings.
You should also invest some time into learning Perl properly.
使用
而不是你的
Use
Instead of your