NAME

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

SYNOPSIS

use Games::QuizTaker;
my $Q=Games::QuizTaker->new(FileName=>"sampleqa");
my %Data=();
my $rData=$Q->load(\%Data);
my ($rQuestions,$rAnswers,$rRandoms)=$Q->generate(\%Data);
$Q->test($rQuestions,$rAnswers,$rRandoms);

DESCRIPTION

new

new("FileName"=>"FILENAME","Delimiter"=>"Delimiter",Answer_Delimiter=>"Delimiter",Score=>"1");

This creates the Games::QuizTaker object and initializes it with two parameters. The FileName parameter is required, and the Delimiter is optional. The Delimiter is what is used to separate the question and answers in the question file. If the Delimiter parameter isn't passed, it will default to the pipe ("|") character. The Answer_Delimiter is used for questions that have more than one correct answer. If the Answer_Delimiter parameter isn't passed, it will default to a space. When answering the questions within the test that have more than one answer, put a space between each answer. There is also a parameter called Scores that also can be passed to the object. By default it is set to 1 and will print out the final score of the quiz when done. It can be set to 0, thus turning it off. This could be done when setting a script up as part of a login script and giving a "Question of the day".

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. It will also check to see if the _Answer_Delimiter parameter is the same as the _Delimiter parameter. If they are the same, then the program will croak.

generate

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

This function will generate the 2 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. 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 internal _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). It will also set the Max_Questions parameter within the object, which will be later used by the test function to keep track of the number of questions printed out.

test

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

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.

EXPORT

None by default

DEBUGGING

There is a single function available for debugging. When called, it will print out the contents of the object and its parameters.

ACKNOWLEDGEMENTS

Special thanks to everyone at http://perlmonks.org for their suggestions and contributions to this module, and to Damian Conway for his excellent book on Object Oriented Perl

Also, I would like to thank Chris Ahrends for his suggestions to improve this module, and to Mike Castle for pointing out a typo in my POD

AUTHOR

Thomas Stanley

Thomas_J_Stanley@msn.com

I can also be found at http://perlmonks.org as TStanley. You can direct any questions relating to this module there.

COPYRIGHT

Copyright (C)2001,2002 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)