在Perl中,如何在命令行上发送CGI参数?

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

为了得到数据,我做了类似的事情:

my $query = new CGI;
my $username = $query->param("the_username");

这似乎不起作用:

$./script.pl the_username=user1

编辑:

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

解决方法

正如我很久以前发现的那样,您确实可以使用 CGI.pm查询字符串参数传递给脚本.我不建议将此作为首选调试方法(最好将可复制的东西保存在文件中,然后将其定向到脚本的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)
);

输出

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

相关文章

1. 如何去重 #!/usr/bin/perl use strict; my %hash; while(...
最近写了一个perl脚本,实现的功能是将表格中其中两列的数据...
表的数据字典格式如下:如果手动写MySQL建表语句,确认麻烦,...
巡检类工作经常会出具日报,最近在原有日报的基础上又新增了...
在实际生产环境中,常常需要从后台日志中截取报文,报文的形...
最近写的一个perl程序,通过关键词匹配统计其出现的频率,让...