Sometimes it is useful to work directly with a students input (before it is converted to a Math Object) to parse it to ensure it is written in the correct form.
For example, to check that powers of a variable have been combined properly, one may check to make sure that the variable only appears once in the expression.
For a problem with a single custom answer checker, this may be accessed through the answer hash, which is the third parameter passed to the checker subroutine. The code would look something like this:
$ans = Formula("x^2")->cmp( checker => sub { my ($correct, $student, $hash) = @_; my $str = $hash->{original_student_ans}; # now $str contains exactly what the student entered } );
But for a problem with a multi answer, I'm having problems accessing anything beyond the first part of the answer. According to this example, the answer hash is passed as the fourth parameter to the checker subroutine (I'm not sure what the third parameter $self is used for, but that may be entirely irrelevant to this question). So I tried using the following code:
$multians = MultiAnswer($num, $den)->with( checker => sub { my ($correct, $student, $self, $hash) = @_; my $str = $hash->{original_student_ans}; # now $str contains exactly what the student entered for the FIRST answer only } );
I've tested this (by inserting $str into error messages) and what seems to happen is that $str will contain exactly what the student entered for the first part of the answer. Is there a way to do something similar for $hash->{original_student_ans} but for each of the subsequent parts of the problem?