在Perl中,如何在命令行上发送CGI参数? [英] In Perl, how do I send CGI parameters on the command line?

查看:90
本文介绍了在Perl中,如何在命令行上发送CGI参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常我从网页上获取数据,但我想从命令行发送以方便调试.

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");

这似乎不起作用:

$ ./script.pl the_username=user1

实际上是上述作品.检查$usernameif语句是错误的(使用==而不是eq).

Actually the above works. The if statement that checked $username was wrong (using == instead of eq).

推荐答案

我很久以前发现,您确实可以使用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:

#!/usr/bin/env perl

use warnings; use strict;

use CGI;

my $cgi = CGI->new;

my $param_name = 'the_username';

printf(
    "The value of '%s' is '%s'.\n",
    $param_name, $cgi->param($param_name)
);

输出:

$ ./t.pl the_username=yadayada
The value of 'the_username' is 'yadayada'.

这篇关于在Perl中,如何在命令行上发送CGI参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆