什么是Perl CGI脚本中PHP的$ _POST的等价物,我该如何使用它?

dex*_*ter 2 php perl

我有两个Perl文件:action.pl另一个是test.pl

action.pl 有一个形式:

print $cgi->header, <<html;
<form action="test.pl" method="post">
html
while (my @row = $sth->fetchrow)
{
print $cgi->header, <<html;
ID:<input name="pid" value="@row[0]" readonly="true"/><br/>
Name: <input name="pname" value="@row[1]"/><br/>
Description : <input name="pdescription" value="@row[2]"/><br/>
Unit Price :<input name="punitprice" value="@row[3]"/><br/>
html
}
print $cgi->header, <<html
<input type="submit" value="update Row">
</form>
html
Run Code Online (Sandbox Code Playgroud)

我应该写什么test.pl才能访问用户提交的表单值?

换句话说,$_POST['pid']在Perl 中PHP的等价物是什么?

And*_*ndy 5

使用CGI和 param()

  use CGI ':standard';
  my $id    = param('id');
Run Code Online (Sandbox Code Playgroud)


Eug*_*ash 5

use CGI;
my $cgi = CGI->new();

for my $p ($cgi->param) {       # loop through all form inputs
    my $val = $cgi->param($p);  # get param's value
    # ...
}
Run Code Online (Sandbox Code Playgroud)

要获取'pid'输入的值,请使用:

$cgi->param('pid');
Run Code Online (Sandbox Code Playgroud)

更新:测试脚本可能如下所示:

#!/usr/bin/perl

use strict;
use warnings;
use CGI;

my $cgi = CGI->new();

printf "%sPid:%s", $cgi->header, $cgi->param('pid');
Run Code Online (Sandbox Code Playgroud)