ファイル名: ./w/m1.cgi

#!/usr/local/bin/perl

#------------------------------------------------------------
$Title = 'm1';
$BODY = '<BODY BGCOLOR="#000000" TEXT="#C0C0C0">';
print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>$Title</TITLE></HEAD>\n";
print "$BODY\n";
$FONT_R = '<font color="#FF0000">';
$FONT_G = '<font color="#00FF00">';
$FONT_C = '</font>';
print "<blockquote>\n";
#------------------------------------------------------------
read(STDIN, $QUERY_DATA, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/,$QUERY_DATA);
foreach $pair (@pairs) {($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/</</g;
$value =~ s/>/>/g;
$value =~ s/\n//g;
$value =~ s/\,//g;
$FORM{$name} = $value;
}

if ($FORM{'action'} eq "true") { &HINT; }
else { print "regular exrression確かめCGI\n"; }

print "<form action=m1.cgi method=POST>\n";
print "<input type=hidden name=action value=true>\n";
print "regular exrression\n";
print "<BR><BR>\n";
print "<input type=text size=20 name=regular>\n";
print "<BR><BR>\n";
print "答え\n";
print "<BR><BR>\n";
print "<input type=text size=20 name=name>\n";
print "<BR><BR>\n";
print "<input type=submit value=OK>\n";
print "<BR><BR>\n";
print "<HR>\n";

sub HINT {

$a = $FORM{'name'};
$b = $FORM{'regular'};

if ($a =~ /$b/) {
&OK;
} else {

print "もう1度\n";
}
}
sub OK {
print "<BR><BR>\n";
print "$FONT_G正解!正解はたくさんあります。$FONT_C\n";
print "<BR><BR>\n";
print "<a href=\"m1.cgi\">BACK</a>\n";
last;
}
#------------------------------------------------------------
print "</blockquote>\n";
print "</BODY>\n";
print "</HTML>\n";
exit;