The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

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","Delimiter"=>"Delimiter",Answer_Delimiter=>"Delimiter");

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.

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,$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 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,$refHash3,$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

Another thank you also goes out to Chris Ahrends for suggesting the idea of having multiple answers for questions.

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 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)