如何从HTML表单中显示多个条目?

时间:2013-05-10 20:01:37

标签: html perl functional-programming cgi

我有一个Perl CGI脚本。我试图在每一行显示用户条目,但它不起作用。这是我到目前为止所做的:

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

print header;
my %hash = (
             'Tyrone'   => 1,
             'Sue'      => 1,
             'Marshall' => 1,
             'Hiroshi'  => 1,
             'Jose'     => 1,
          )


print start_html(
    -title => 'Students in Class'
);

# Process an HTTP request
my $rollcall = param("names");
my @students_in_class = split(/;/, $rollcall);

foreach my $student (@students_in_class){
   if (exists $hash{$student}) {
       print h1('One student is '. $student . '<br>');
   } else {
       print h1('That student was sick today'. '<br>');
     }
}

如果用户在搜索栏中输入以下内容:Tyrone;Tommy;Marhshall

CGI应该产生以下输出

期望输出

一名学生是Tyrone

那个学生今天病了

一名学生是马歇尔


由于某种原因,它不起作用。

1 个答案:

答案 0 :(得分:2)

哈希定义后你缺少分号,

my %hash = (
         'Tyrone'   => 1,
         'Sue'      => 1,
         'Marshall' => 1,
         'Hiroshi'  => 1,
         'Jose'     => 1,
      );