in reply to (jeffa) Re: Efficient Rating of Test Answers
in thread Efficient Rating of Test Answers
You are describing the general concept of a 'Dispatch Table'. While very useful at times I think that's a little overkill here. Your subroutines do exactly the same thing - add a number - and only this number differs. So why not just store the number as proposed by VSarkiss. Your code would then simplify to
I think I still prefer the regex solution by enoch in this easy case where the keys/answers are so 'handy' to match.my %lookup = ( # no longer a dispatch g6 => 1, g7 => 1, g8 => 1, g9 => 1, g0 => 0.5, # ... ); my $total = 10; $total += exists($lookup{'g6'})? $lookup{'g6'} : 0; print $total, "\n";
-- Hofmator
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(jeffa) 3Re: Efficient Rating of Test Answers
by jeffa (Bishop) on Aug 14, 2001 at 19:16 UTC |