2013-05-10 63 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

相關問題