1

我有一个 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

那个学生今天病了

一名学生是马歇尔


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

4

1 回答 1

2

您在哈希定义后缺少分号,

my %hash = (
         'Tyrone'   => 1,
         'Sue'      => 1,
         'Marshall' => 1,
         'Hiroshi'  => 1,
         'Jose'     => 1,
      );
于 2013-05-10T20:21:21.353 回答