如何在perl中获取POST值 [英] how to get POST values in perl
本文介绍了如何在perl中获取POST值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试自定义脚本,并且需要使用perl从表单中获取POST值。
我没有perl的背景,但是这是一件相当简单的事情,所以我想应该不难。
I am trying to customize a script and need to get a POST value from a form using perl. I have no background of perl but this is a fairly simple thing so I guess it should not be hard.
这是我编写的php版本的代码希望在PERL中拥有:
This is the php version of the code I would like to have in PERL:
<?php
$download = ($_POST['dl']) ? '1' : '0';
?>
我知道这可能与PERL版本完全无关,但我想可以澄清一下
I know this may not be at all related to the PERL version but it could help I guess clarifying what exactly I am looking to do.
推荐答案
好吧,在这种情况下,请看一下下面的简单代码:这对您有帮助:
Well, in that case please have a look at this simple code: This would help you:
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
sub output_top($);
sub output_end($);
sub display_results($);
sub output_form($);
my $q = new CGI;
print $q->header();
# Output stylesheet, heading etc
output_top($q);
if ($q->param()) {
# Parameters are defined, therefore the form has been submitted
display_results($q);
} else {
# We're here for the first time, display the form
output_form($q);
}
# Output footer and end html
output_end($q);
exit 0;
# Outputs the start html tag, stylesheet and heading
sub output_top($) {
my ($q) = @_;
print $q->start_html(
-title => 'A Questionaire',
-bgcolor => 'white');
}
# Outputs a footer line and end html tags
sub output_end($) {
my ($q) = @_;
print $q->div("My Web Form");
print $q->end_html;
}
# Displays the results of the form
sub display_results($) {
my ($q) = @_;
my $username = $q->param('user_name');
}
# Outputs a web form
sub output_form($) {
my ($q) = @_;
print $q->start_form(
-name => 'main',
-method => 'POST',
);
print $q->start_table;
print $q->Tr(
$q->td('Name:'),
$q->td(
$q->textfield(-name => "user_name", -size => 50)
)
);
print $q->Tr(
$q->td($q->submit(-value => 'Submit')),
$q->td(' ')
);
print $q->end_table;
print $q->end_form;
}
这篇关于如何在perl中获取POST值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文