
Quiz - Questions wrapper.

use Quiz;
use strict;
my %qz = ('3 * 2' => '6', '2 + 2' => '4',
'What is the capital of England' => 'London',
'What are white and fluffy and float in the sky' => 'clouds',
'7 - 2' => '5',
);
my $quiz = Quiz->new(%qz);
$quiz->prompt('Question: '); #going to use our own prompt.
while ($quiz->unanswered_questions) {
print $quiz->next_question, "\n";
$_ = <>;
if ($quiz->check_guess($_)) {
print $quiz->{right_message};
} else {
print $quiz->{wrong_message};
}
}
$quiz->finished;
print $quiz->results;
exit;
Create new Quiz:
my $qz = Quiz->new(%question_n_answers);
eg;
$qz->prompt('What is the sum of..:');
Are there any left?
my $qs_left = $qz->unanswered_questions;
Basic loop through all questions...
while (1) {
print $qz->next_question;
}
or
while ($qz->unanswered_questions) {
print $qz->next_question;
}
Returns current question:
my $qstn = $qz->question;
Returns current answer:
my $ans = $qz->answer;
Returns number of correct_questions so far.
print "Got at least ten right!\n" if $qz->correct_questions >= 10;
Insert guess into system.
my $guess = $qz->guess('some answer');
Better is to check the guess...
my $result = $qz->check_guess('some other answer');
Signal end of quiz:
$qz->finished;
Simple print out of Quiz results:
print $qz->results;
Also prints out info on each question if asked:
print $qz->results('question');