I think you need to take a step back from the problem,
and reconsider how you want to represent this data.
You might retrieve multiple answers to a question
from your online form and place them into a string
next to each other using the join command so that selecting
both A and B might give you $form[5] = "AB".
You would then loop through the questions checking the
length of this string, which is going to be greater than
1 if multiple choices have been selected. Use a regular
expression to see if the correct choice is one of those
included in the string, with something like
$ok = $form[$i] =~ /$ans[$i]/; # e.g. $ans[5] is "A"
$points += 0.5 if $ok;
There are other ways to do it of course, for example you
could use the index command which returns -1 if it doesn't
find the substring for which you are looking. You could
also keep the form data in a hash, or request the
multiple values to be returned into an array. See the
documentation for CGI.pm as described in this node
for more information about that. |