in reply to Calculate grades
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Calculate grades
by Anonymous Monk on Apr 02, 2004 at 01:36 UTC | |
by DamnDirtyApe (Curate) on Apr 02, 2004 at 01:48 UTC | |
by Anonymous Monk on Apr 02, 2004 at 01:59 UTC |
In Section
Seekers of Perl Wisdom