加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

如何在perl中获取POST值

发布时间:2020-12-15 21:43:33 所属栏目:大数据 来源:网络整理
导读:我正在尝试自定义脚本,需要使用perl从表单中获取POST值. 我没有perl的背景,但这是一个相当简单的事情,所以我想它应该不难. 这是我希望在PERL中拥有的代码的php版本: ?php$download = ($_POST['dl']) ? '1' : '0';? 我知道这可能与PERL版本无关,但它可以帮助
我正在尝试自定义脚本,需要使用perl从表单中获取POST值.
我没有perl的背景,但这是一个相当简单的事情,所以我想它应该不难.

这是我希望在PERL中拥有的代码的php版本:

<?php
$download = ($_POST['dl']) ? '1' : '0';
?>

我知道这可能与PERL版本无关,但它可以帮助我猜清楚我到底要做什么.

解决方法

那么,在这种情况下,请看一下这个简单的代码:这可以帮助你:
#!/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('&nbsp;')
    );
    print $q->end_table;
    print $q->end_form;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读