通常我从网页获取数据,但我想从命令行发送它以方便调试。
为了获取数据我做了类似的事情:
my $query = new CGI;
my $username = $query->param("the_username");
这似乎不起作用:
$ ./script.pl the_username=user1
EDIT:
实际上上面的方法有效。这if
检查过的声明$username
是错误的(使用==
代替eq
).
正如我很久以前发现的那样,您确实可以使用以下命令将查询字符串参数传递给脚本CGI.pm http://search.cpan.org/perldoc/CGI。我不推荐将此作为首选调试方法(最好将可复制的内容保存在文件中,然后将其定向到STDIN
脚本),但是,它确实有效:
#!/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)
);
Output:
$ ./t.pl the_username=yadayada
The value of 'the_username' is 'yadayada'.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)