NAME

Games::QuizTaker - Create and take your own quizzes and tests

SYNOPSIS

use Quiz::Taker;
my $Q=Quiz::Taker->new({-FileName=>"sampleqa"});
my %Data=();
my $rData=$Q->load(\%Data);
my ($rQuestions,$rAnswers,$rLengths,$rRandoms)=$Q->generate(\%Data);
$Q->test($rQuestions,$rAnswers,$rLengths,$rRandoms);

DESCRIPTION

new

new({-FileName=>"FILENAME",-Delimitor=>"Delimitor"});

This creates the Games::QuizTaker object and initializes it with two parameters. The -FileName parameter is required, and the -Delimitor is optional. The -Delimitor is what is used to separate the question and answers in the question file. If the -Delimitor parameter isn't passed, it will default to the pipe ("|") character.

load

$refHash=$QT->load(\%Data);

This function will load the hash with all of the questions and answers from the file that you specify when you create the object. It also sets another parameter within the $QT object called -FileLength, which is the total number of questions within the file.

generate

($refHash1,$refHash2,$refHash3,$refArray1)=$QT->generate(\%Data,$Max);

This function will generate the 3 hashes and 1 array needed by the test function. The first reference ($refHash1) are the questions that will be asked by the test function. The second reference ($refHash2) are the answers to those questions. The third reference ($refHash3) is the length of the array that is the value for each key of $refHash1. And $refArray1 is a sequence of random numbers that is generated from the total number of questions ($Max) that you wish to answer. The $refArray1 is also randomized further after its generation by the _shuffle function which is a Fisher-Yates shuffle. If the maximum number of questions you wish to answer on the quiz ($Max) is not passed to the function, it will default to the maximum number of questions in the file (determined by the -FileLength parameter within the object).

test

$QT->test($refHash1,$refHash2,$refHash3,$refArray1,$Max);

This function will print out each question in the Questions hash, and wait for a response. It will then match that response against the Answers hash. If there is a match, it will keep track of the number of correct answers, and move on to the next question, other wise it will give the correct answer, and go to the next question. After the last question, it will pass the number correct and the max number of questions on the test to the _Final function, which prints out your final score. The $Max variable is optional to be passed and will default to the total number of questions in the original question file.

EXPORT

None by default

ACKNOWLEDGEMENTS

Special thanks to everyone at http://perlmonks.org for their suggestions and contributions to this module.

AUTHOR

Thomas Stanley

Thomas_J_Stanley@msn.com

COPYRIGHT

Copyright (C)2001 Thomas Stanley. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

perl(1)