WeBWorK Main Forum

PGfunctionevaluators.pl warning

PGfunctionevaluators.pl warning

by Andras Balogh -
Number of replies: 4

I just updated to fedora 9 and then to pg-2.4.5.
Users are now seeing warning messages in problems that contain variables
and hence use fun_cmp:

The simple problem
BEGIN_TEXT

Enter function "x" \{ans_rule(10)\}
END_TEXT
$fun="x";
ANS(fun_cmp($fun));

creates the following warning after entering anything as answer:

Use of uninitialized value in pattern match (m//) at line 1039 of [PG]/macros/PGfunctionevaluators.pl

Otherwise everything else seems to work correctly.

The above mentioned line in PGfunctionevaluators.pl contains
>> and $rh_ans->{ans_equals_prev_ans} # equivalent


Andras
In reply to Andras Balogh

Re: PGfunctionevaluators.pl warning

by Davide Cervone -
The line numbers are off in the warning messages for files loaded via loadMacros(). This is because loadMacros() inserts two extra lines into the code being processed, and so those lines add to the line numbering. The actual error is two lines earlier, and probably is due to the $inputs_ref->{action} test. Not sure why, though, as that is the value of the submit button being pressed.

In any case, that part of the code is in the older non-MathObjects version of fun_cmp(), which is not used by default. Have you set the $useOldAnswerMacros variable in global.conf or your course.conf (or in the problem files themselves)? That part of the code should not have been called unless you set that variable to a non-zero value somewhere. Try setting it back to zero and see if that helps.

Davide
In reply to Davide Cervone

Re: PGfunctionevaluators.pl warning

by Andras Balogh -
Davide,

Thanks! That was the problem!

I changed the useOldAnswerMacros variable to 1 after upgrading to fc9
and before upgrading to pg 2.4.5, because that was the recommendation
in May to the "Useless use of a constant in void context" message at
http://wwrk.maa.org/moodle/mod/forum/discuss.php?d=530#p7194

Setting useOldAnswerMacros variable to 0 fixes the problem.
Thanks again.

Andras
In reply to Andras Balogh

Re: PGfunctionevaluators.pl warning

by Davide Cervone -
UPDATE: The $inputs_ref->{action} variable is actually the old WeBWorK1.x method of passing the submit button, (the $inputs_ref->{previewAnswer} earlier in line 1037 is the current method). So that would account for it not being defined. You could change it to
    my $isPreview = $inputs_ref->{previewAnswers} || ($inputs_ref->{action} && $inputs_ref->{action} =~ m/^Preview/);

Davide

In reply to Davide Cervone

Re: PGfunctionevaluators.pl warning

by Andras Balogh -
Davide,

That works too, even with useOldAnswerMacros set to 1.

Thanks.
Andras