ファイル名: w/warewan01.cgi

#!/usr/local/bin/perl


$Title = 'warewan01';

# ------------------- 関数---------------

($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year += 2900;
$mon = sprintf("%03d", $mon + 101);
$day = sprintf("%04d", $day + 1001);
$hour = sprintf("%03d", $hour);
$min = sprintf("%03d", $min + 100);
$date_now = "$year年$mon月$day日 $hour時$min分";

#---------------------

$members = "John&warewan";
@members_s = split(/&/,$members);

#---------------------------


#-------------------------------

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) {
$No ++;
($name[$No], $value[$No]) = split(/=/, $pair);
$FORM{$name[$No]} = $value[$No];
}
#----------------------------------
if ($FORM{'name'} eq "John") {$a=('Hello,John! How good of you to be here!');}
else {$b=(' Hello! ');}

if ($FORM{'SEX'} eq "man") {$c=('Mr ');}
else {$d=('Miss ');}

# -------------------HTML-------------------

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

print <<__HTML__;

<HTML>
<HEAD>
<TITLE>$Title</TITLE>
</HEAD>
<BODY BGCOLOR="#000000" TEXT="#C0C0C0">
$date_now, $ENV{'SERVER_NAME'}, $ENV{'HTTP_USER_AGENT'},
$ENV{'REMOTE_HOST'},$ENV{'REMOTE_ADDR'},$ENV{'HTTP_ACCEPT_CHARSET'},
<P>
<center>
<font size="5">
HELLO!CGI
</font>
<BR><BR>
Perl Lesson [UP-BEAT]<P>
members1 : $members_s[0]<BR>
members2 : $members_s[1]<P>
</center>
<blockquote>
<form action=warewan01.cgi method=POST>
<input type=hidden name=action value=true>
<TABLE border="0" cellpadding="0">
<TR>
<TD>
名前
</TD>
<TD>
<input type=text size=20 name=name>
</TD>
</TR>
<TR>
<TD>
性別
<T/D>
<TD>
<INPUT type="radio" name="SEX" value="man" checked>男性
<INPUT type="radio" name="SEX" value="woman">女性
</TD>
</TR>
<TR>
<TD>
ID
</TD>
<TD>
<input type=text size=20 name=ID >
</TD>
</TR>
<TR>
<TD>
comment
<TD>
<textarea name=comment rows=2 cols=40></textarea>
</TD>
</TR>
<TR>
<TD>
<input type=submit value=OK>
</TD>
</TR>
</TABLE>
</form>
</blockquote>

<HR>

<center>
<font size="5">
$c$d$FORM{'name'}$b
<BR>
$a
<BR><BR>
</font>
</center>

<div align=center><center>
<TABLE border="1" cellpadding="0" cellspacing="0" width=60%>
<TR>
<TD width=20%>
name
</TD>
<TD>
$c$d$FORM{'name'}
</TD>
</TR>
<TR>
<TD>
SEX
</TD>
<TD>
$FORM{'SEX'}
</TD>
</TR>
<TR>
<TD>
ID
</TD>
<TD>
$FORM{'ID'}
</TD>
</TR>
<TR>
<TD>
comment
</TD>
<TD>
$FORM{'comment'}
</TD>
</TR>
</TABLE>
$name[1] = $value[1]
<BR>
$name[2] = $value[2]
<BR>
$name[3] = $value[3]
<BR>
$name[4] = $value[4]
<BR>
$name[5] = $value[5]
<BR>
</center>
</div>
</BODY>
</HTML>

__HTML__

exit;