## WeBWorK Problems

### Newly-authored problem HASH error

by D. Brian Walton -
Number of replies: 2
Ok, this is strange. I've been editing new problems and have started getting some strange errors about something not being initialized. (Existing problems in the library don't seem to trigger the same error.)

I minimized the code of the problem and realized that the error comes from including "PGcourse.pl" which only includes some randomization. Excluding the macro file makes the problem work.

Here is the contents of PGcourse.pl, which I thought I just copied from another resource.

Does anyone see what I might have done improperly here?

#### Allow a Guest or Observer to always get a new version of problem.
ProblemRandomize( when => "Always", onlyAfterDue => 0, style => "Button" )
if ($guest or$observe) ;
#### Allow everybody else (e.g., a student) to get a new version (for more practice)
#### after correct answer(s) to first (scored) version OR after the assignment's due date
$when = (time >=$main::dueDate ? "Always" : "Correct");
ProblemRandomize( when => $when, onlyAfterDue => 0, style => "Button" ) if not ($guest or \$observe) ;
Using WW 2.12 and PG 2.12.
Problems are being edited and saved in the templates/local directory.

## Warning messages

• Processing of this PG problem was not completed. Probably because of a syntax error. The translator died prematurely and no PG warning messages were transmitted. at /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm line 752. Odd number of elements in anonymous hash at /opt/webwork/webwork2/lib/WeBWorK/Utils/AttemptsTable.pm line 180. Use of uninitialized value in anonymous hash ({}) at /opt/webwork/webwork2/lib/WeBWorK/Utils/AttemptsTable.pm line 180.

### Error messages

Can't use string ("answersSubmitted") as an ARRAY ref while "strict refs" in use at /opt/webwork/webwork2/lib/WeBWorK/Utils/AttemptsTable.pm line 202.

### Call stack

The information below can help locate the source of the problem.

• in WeBWorK::Utils::AttemptsTable::_init called at line 190 of /opt/webwork/webwork2/lib/WeBWorK/Utils/AttemptsTable.pm
• in WeBWorK::Utils::AttemptsTable::new called at line 315 of /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm
• in WeBWorK::ContentGenerator::Problem::attemptResults called at line 1846 of /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm
• in WeBWorK::ContentGenerator::Problem::output_summary called at line 155 of /opt/webwork/webwork2/lib/WeBWorK/Template.pm
• in WeBWorK::Template::template called at line 561 of /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator.pm
• in WeBWorK::ContentGenerator::content called at line 356 of /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm
• in WeBWorK::ContentGenerator::Problem::content called at line 233 of /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator.pm
• in WeBWorK::ContentGenerator::go called at line 382 of /opt/webwork/webwork2/lib/WeBWorK.pm

## Warning messages

• Processing of this PG problem was not completed. Probably because of a syntax error. The translator died prematurely and no PG warning messages were transmitted. at /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm line 752.

### Error messages

Can't use an undefined value as a HASH reference at /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/ProblemUtil/ProblemUtil.pm line 143.

### Call stack

The information below can help locate the source of the problem.

• in WeBWorK::ContentGenerator::ProblemUtil::ProblemUtil::process_and_log_answer called at line 765 of /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm
• in WeBWorK::ContentGenerator::Problem::pre_header_initialize called at line 214 of /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator.pm
• in WeBWorK::ContentGenerator::go called at line 382 of /opt/webwork/webwork2/lib/WeBWorK.pm

In reply to D. Brian Walton

### Re: Newly-authored problem HASH error

by D. Brian Walton -
I had a sudden flash of insight (ok, just a hunch) and changed the order that the macros were being loaded. When I put PGcourse.pl at the end, it looks like everything is now working.