2011-08-25 71 views
0

我有一个小型的perl webserver,它调用了http_handler.pl,它有一些代码可以进行表单输入。如何将表单输入传递给perl脚本的子例程

对于这部分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?中),但是如何更改该打印语句以将表单输入传递给hello_post.pl子例程,然后显示这一页?

我实际上最终想要做的不同于只输入/显示返回的姓名,但我只是在拼凑其他人的代码,以查看我是否能够得到这个概念...任何帮助将是伟大的!谢谢!

这里有3个文件(pl-websrv.pl,http_handler.pl和hello_post.pl)

http://pastebin.com/iPN3WwqC

回答

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"; 
} 
相关问题