NAME
Quiz - Questions wrapper.
SYNOPSIS
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;
- new
-
Create new Quiz: my $qz = Quiz->new(%question_n_answers);
eg; $qz->prompt('What is the sum of..:');
- unanswered_questions
-
Are there any left? my $qs_left = $qz->unanswered_questions;
- next_question
-
Basic loop through all questions... while (1) { print $qz->next_question; } or while ($qz->unanswered_questions) { print $qz->next_question; }
- question
-
Returns current question: my $qstn = $qz->question;
- answer
-
Returns current answer: my $ans = $qz->answer;
- correct_questions
-
Returns number of correct_questions so far. print "Got at least ten right!\n" if $qz->correct_questions >= 10;
- guess
-
Insert guess into system. my $guess = $qz->guess('some answer');
- check_guess
-
Better is to check the guess... my $result = $qz->check_guess('some other answer');
- finished
-
Signal end of quiz: $qz->finished;
- results
-
Simple print out of Quiz results: print $qz->results; Also prints out info on each question if asked: print $qz->results('question');
2 POD Errors
The following errors were encountered while parsing the POD:
- Around line 49:
'=item' outside of any '=over'
=over without closing =back
- Around line 84:
Unknown directive: =prompt