I'm tempted to take this approach (assuming you're only dealing with single letter answers):
#! /usr/bin/perl
use strict;
my %test = (
question1 => 'a',
question2 => 'b',
question3 => 'a',
);
#my hash of arrays with multiple answers
my %answers = (
question1 => [
'a'
],
question2 => [
'b',
'd'
],
question3 => [
'b'
],
);
my $q_count = keys %answers;
my $grade = 0;
for ( keys %answers ) {
$grade++ if "@{$answers{$_}}" =~ /$test{$_}/i;
}
print "You got $grade out of $q_count right.$/";
_______________
DamnDirtyApe
Those who know that they are profound strive for clarity. Those who
would like to seem profound to the crowd strive for obscurity.
--Friedrich Nietzsche