Hi--
The code below, which defines an answer evaluator, doesn't work. The problem is the + signs. If I replace
$ans =~ s/\s+//g
with
$ans =~ s/ //g
and remove the + sign in the if test, everything is fine (except, of
course, that then the answer I want from the students doesn't match
what's in the if test). I fixed this particular problem by replacing
the m///
by a substring test, but how do you program around it in general? And
why does it happen? (I also tried $ans =~ s/\+/X/ which doesn't do
anything either. None of these things results in an error message; the
code just fails silently.)
Thanks again,
Steve
$anseval = sub {
my $student_ans = shift;
my $correct = 0;
my $ans = $student_ans;
$ans =~ s/\s+//g; # FAILS
$ans =~ tr/[a-z]/[A-Z]/;
if ($ans =~ /^P\+PRT$/ || $ans =~ /^P\(1\+RT\)$/) {$correct = 1;} # FAILS
my $anshash = new AnswerHash();
$anshash->{'score'} = $correct;
$anshash->{'correct_ans'} = "P+Prt or P(1+rt)";
$anshash->{'student_ans'} = $student_ans;
$anshash->{'type'} = "SPC";
return $anshash;
};
<| Post or View Comments |>
|