Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Calculate grades

by DamnDirtyApe (Curate)
on Apr 02, 2004 at 01:15 UTC ( [id://341855]=note: print w/replies, xml ) Need Help??


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
    Hello DamnDirtyApe
    Could you please decode for me the regexp, so I can adapt it?
    Actually some others test, have the answer type, not the option (one letter), so I could change the regexp. Thanks

      There's not really anything to decide. Putting an array inside quotes returns a scalar with the array contents, so if $foo == [ 'a', 'b' ], then "@$foo" == "ab". The regexp searches that string for the answer, so if the answer given was "b", what were essentially doing is "ab" ~= /b/i. This will match, and the correct grade counter is incremented.

      Make sense?


      _______________
      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
        yeap, thanks

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://341855]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-19 15:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found