return to first page linux journal archive
keywordscontents

#!/usr/bin/perl -w

# Turn on strict error checking
use strict;
use diagnostics;

# CGI.pm is available from CPAN, at
# http://www.perl.com/CPAN
use CGI;  

# Include our object
use QuizQuestions;

# Where should we send people if
# they want to play again?
my $question_cgi = "askquestion.pl";

# Where should we send people if they
# don't want to play again?
my $final_html = "/quizend.html";

# -------------------------------
# Create a new CGI object, and output an
# initial MIME header
my $query = new CGI;
print $query->header("text/html");
print $query->start_html(-title => "Quiz");

# Get the quiz name
my $quiz_name = $ENV{"QUERY_STRING"};

# Create a new QuizQuestions object, using
# the name of our quiz
my $quiz = new QuizQuestions($quiz_name);

# Now retrieve the question that we want
my $question_number = 
   $query->param("questionNumber");

my ($question, $answerA, $answerB, $answerC,
    $answerD, $rightAnswer, $questionNumber) 
    = $quiz->getQuestion($question_number);

# Did the user answer correctly?
    if ((lc ($query->param("answer"))) eq
      (lc $rightAnswer))
{
    print "<P>Yay! You got it right!</P>\n";
}
else
{
    # Get the right answer
    my $rightAnswerText = eval('$answer' .
       $rightAnswer);

    print "<P>Sorry, but the correct answer";
    print " was \"$rightAnswer\" ";
    print "($rightAnswerText).</P>\n";
}

print "<P>You can <a ";
print "href=\"$question_cgi?$quiz_name\">";
print "play again</a>, ";
print "or <a href=\"$final_html\">";
print "end the game</a> now.</P>\n";

print $query->end_html;