I am trying to build a simple custom answer evaluator template to get things started, but have run into trouble. I started with some (really old?) examples which had some typos/issues, and merged that with a palindrome example (don't remember where that came from...original distro maybe?)
The problem code at the bottom works, but when I try adding a passed correct answer by doing (what seems to me) to be some of the obvious, I get errors.
For example I try
$test_sub = sub {
my $CorrectAnswer = shift @_;
my $in = shift @_;
etc.
ANS($ans->$test_sub);
I get
Warning messages
Error in Translator.pm::process_answers: Answer AnSwEr1:
Unrecognized evaluator type |AnswerHash| at /opt/webwork/pg/lib/WeBWorK/PG/Translator.pm line 1156
Error in Translator.pm::process_answers: Answer AnSwEr1:
Answer evaluators must return a hash or an AnswerHash type, not type || at /opt/webwork/pg/lib/WeBWorK/PG/Translator.pm line 1161
I suspect my problem may be in how I'm trying to use PERL but I don't have access to any PERL gurus. I'd appreciate any help or any pointers to working simple examples of custom evaluators that have parameters passed from the question to the evaluating function. For the record, I am using webwork-2.4.1.
Thanks in advance for any help.
-Mike Gallis
Functioning example below:
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGanswermacros.pl",
);
TEXT(&beginproblem);
$showPartialCorrectAnswers = 1;
$ans="Mozart";
BEGIN_TEXT
test_sub test:enter $ans $BR
\{ans_rule(60) \}
END_TEXT
$test_sub = sub {
my $in = shift @_;
my $CorrectAnswer = "Mozart";
my $correctQ = ($in eq $CorrectAnswer ) ? 1: 0;
my $ansMsg = "the message";
my $rh_answer = new AnswerHash( score => $correctQ,
correct_ans => $CorrectAnswer,
student_ans => $in,
ans_message => $ansMsg,
type => 'custom'
);
$rh_answer;
};
ANS($test_sub();
ENDDOCUMENT();