如何从perl脚本传递表单输入到子例程

时间:2011-08-25 16:54:34

标签: forms perl

我有一个小的perl网络服务器,它调用http_handler.pl,它有一些代码可以进行表单输入。

对于http_handler中的这部分:

print $fh '<FORM action="/hello_post.pl" method="POST">First Name: <input type="text" name="first_name"> <br> Last Name: <input type="text" name="last_name"> <input type="submit" value="Submit"></FORM>';

....如何将用户输入传递给hello_post.pl子例程?我必须要求hello_post.pl(在http_handler.pl或pl-websrv.pl?中),但是如何更改该print语句以使表单输入刚刚传递给hello_post.pl子例程然后显示在页面?

我实际上想要做的事情是不同的,只是输入/显示后面的名字,但我只是拼凑其他人的代码,看看我是否可以得到这个概念...任何帮助都会很棒!谢谢!

以下是3个文件(pl-websrv.pl,http_handler.pl和hello_post.pl)

http://pastebin.com/iPN3WwqC

1 个答案:

答案 0 :(得分:0)

首先写一个类似下面的hello_post.pl文件,它只是回显所有参数。

#!/usr/bin/perl
use warnings;
use strict;
use CGI::Carp qw(fatalsToBrowser);
use CGI;

my $cgi = CGI->new();

print "Content-Type: text/plain\n\n";

print "hello_post.pl output:\n";

my $params = $cgi->Vars();
foreach my $arg ( sort keys %$params ) {
   print "$arg  ==>  ", $cgi->param($arg), "\n";
}
相关问题