#!/usr/local/bin/perl # output type print "Content-type: text/html\n\n"; # Read the master word list &readinfile; # IF NO COMMAND, WRITE INITIAL DIALOGUE if ($ENV{'QUERY_STRING'} eq '') { $firsttime = 1; $donum = int(rand($sumtot)); &writeout; exit; } # SHOW WORD LIST -- IN NEW WINDOW if ($ENV{'QUERY_STRING'} eq 'wordlist') { $valueof{$rootname} = $rootdef; print "\n"; print "\n"; foreach $rootval (sort keys %shortvalueof) { print "
$rootval$shortvalueof{$rootval}\n"; } print "\n"; exit; } # FORM WAS SUBMITTED # Get Form Information &parse_form; # SETS THE WORD NUMBER $donum = $FORM{'questnum'}; $showroot = $namefor[$donum]; #correct answer if (lc $FORM{'answergiven'} eq lc $valueof{$showroot}) { # ANOTHER QUESTION $correctanswer = 1; $donum = int(rand($sumtot)); &writeout; } #wrong answer else { #Same question number (donum) will be reused &writeout; } ######################## # Read in the word file sub readinfile { open (READIN, "rootlist.txt"); while () { $line = "$_"; chomp $line; ($rootname, $rootdef, $examples) = split(/\t/, $line); # REMOVE EXTRA CHARACTERS FROM THE ROOT $shortroot = $rootname; $shortroot =~ s/[^a-zA-Z0-9 ]//g; $valueof{$rootname} = $rootdef; $examplesof{$rootname} = $examples; $shortvalueof{$shortroot} = $rootdef; $namefor[$sumtot] = $rootname; $sumtot++; } } #EOS ##################### # WRITE OUT THE HTML sub writeout { print ""; print "

"; if ($correctanswer) { print "(That's right, $showroot means $FORM{'answergiven'}).

\n"; } else { unless ($firsttime) { print "Sorry, please try again.

" } } print "What does this root mean?

\n"; print "

$namefor[$donum]

\n"; print "

Some examples are: $examplesof{$namefor[$donum]}

\n"; print "
\n"; print "\n"; print "\n"; print "

\n"; print "\n"; print "


\n"; print "
\n"; print "

\n"; print "\n"; print "


\n"; print "
\n"; print "

\n"; print "\n"; print "


\n"; } # EOS ####################### # Parse Form Subroutine sub parse_form { # Get the input read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the name-value pairs @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); # Un-Webify plus signs and %-encoding $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s///g; chomp $value; $FORM{$name} = $value; } }