ファイル名: w/foreach.cgi

#!/usr/local/bin/perl


$Title = 'foreach';

# ------------------- 関数---------------
if ($ENV{'REQUEST_METHOD'} eq "POST") {
read(STDIN, $QUERY_DATA, $ENV{'CONTENT_LENGTH'});
} else { $formdata = $ENV{'QUERY_STRING'}; }

@pairs = split(/&/,$QUERY_DATA);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$FORM{$name} = $value;
}
if ($FORM{'name'} eq "John") {$a=('Hello,John! How good of you to be here!');}
else {$b=('Hello! ');}
# -------------------HTML-------------------

print "Content-type: text/html\n\n";

print <<__HTML__;

<HTML>
<HEAD>
<TITLE>$Title</TITLE>
</HEAD>
<BODY BGCOLOR="#000000" TEXT="#C0C0C0">

<BR><BR>
<center>
<font size="5">
$b$FORM{'name'}
<BR><BR>
$a
<BR><BR>
</font>
</center>
<blockquote>
<font size="4">
1 name $FORM{'name'}<BR>
2 ID $FORM{'ID'}<BR>
3 comment $FORM{'comment'}<BR>
</font>
</blockquote>
</BODY>
</HTML>

__HTML__

exit;