2013-05-10 62 views
1

我有一个Perl CGI脚本。我试图在每一行显示用户条目,但它不起作用。这是我到目前为止有:如何显示HTML表单中的多个条目?

#!/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

一学生是泰隆

那个学生今天生病了

一个学生是马歇尔


出于某种原因,这是行不通的。

+0

完全不工作?尝试'perl -c yourperl.cgi' – 2013-05-10 20:13:51

+0

语法错误在studentsInclass.cgi行15附近“) print” studentsInclass.cgi有编译错误。 – cooldood3490 2013-05-10 20:19:07

回答

2

你错过哈希定义后分号,

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

谢谢。有点高级的问题,但我做了nooby语法错误。 – cooldood3490 2013-05-10 20:27:02

相关问题