在 Perl 中,如何在命令行上发送 CGI 参数?
通常我从网页获取数据,但我想从命令行发送它以方便调试。
为了获取数据,我做了类似的事情:
my $query = new CGI;
my $username = $query->param("the_username");
这似乎不起作用:
$ ./script.pl the_username=user1
编辑:
实际上上面的方法有效。检查 $username
的 if
语句是错误的(使用 ==
而不是 eq
)。
Normally i get the data from a webpage but i want to send it from the command line to facilitate debugging.
To get the data i do something like:
my $query = new CGI;
my $username = $query->param("the_username");
this doesn't seem to work:
$ ./script.pl the_username=user1
EDIT:
Actually the above works. The if
statement that checked $username
was wrong (using ==
instead of eq
).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如我很久以前发现的那样,您确实可以使用 CGI.pm 将查询字符串参数传递给脚本。我不推荐将此作为首选调试方法(最好将可复制的内容保存在文件中,然后将其定向到脚本的
STDIN
),但是,它确实有效:输出:
As I found out long time ago, you can indeed pass query string parameters to a script using CGI.pm. I am not recommending this as a preferred debugging method (better to have replicable stuff saved in files which are then directed to the
STDIN
of the script), however, it does work:Output:
CGI 从标准输入读取变量。
请参阅 CGI.pm 文档的这一部分:
http://search。 cpan.org/dist/CGI/lib/CGI.pod#DEBUGGING
CGI reads the variables from standard input.
See this part of the CGI.pm documentation:
http://search.cpan.org/dist/CGI/lib/CGI.pod#DEBUGGING