Ughh! No matter how you slice it, that's an icky problem. I try to avoid those nasty if-elsif-else statements with a hash table. japhy calls it a 'Dispatch Table', which sounds like a great name to me. The idea is that the keys in the hash point to subroutines:
my %dispatch = ( g6 => \&add_one, g7 => \&add_one, g8 => \&add_one, g9 => \&add_one, g0 => \&add_half, g1 => \&add_half, g2 => \&add_half, g3 => \&add_half, g4 => \&add_half, g5 => \&add_half, k0 => \&add_half, k1 => \&add_half, k2 => \&add_half, k3 => \&add_half, k4 => \&add_half, k5 => \&add_half, ); sub add_one { my $total = shift; $total += 1; return $total; } sub add_half { my $total = shift; $total += 1; return $total; }
And you access the table like so:
my $total = 10; $total = $dispatch{'g6'}->($total); $total = $dispatch{'k5'}->($total); print $total, "\n";
This is not a complete solution for you, but it is a start.

----------------------------------------------------
 perl -le '$x="jeff";$x++ for(0..4482550);print $x'
----------------------------------------------------

In reply to (jeffa) Re: Efficient Rating of Test Answers by jeffa
in thread Efficient Rating of Test Answers by rvf

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.