Perl and PG
This tutorial on Perl and PG will familiarize you with the basic constructs
used most often when writing WebWork questions. It is not comprehensive and
does not explain everything. We will often provide links at the bottom
of each page in case you want to know more details. You could also use Google
to search for more details, or a textbook on Perl. If part of this tutorial
is too difficult, has insufficient detail, or starts at too high a level,
please let me know by emailing paulZwebZworkATgmail.com (remove the Z's
-- they're to prevent spam).
PERL stands for Practical Extraction and Report Language. PG stands
for Problem Generation, and it is a language built on Perl to write
WebWork homework questions. Each PG file is essentially a Perl
script that produces output in HTML or PDF (via pdfLaTeX). MathObjects are
a recently developed part of the PG language, and will be discussed
separately.
Perl Basics
Perl has strings, which are enclosed by single quotes (which are straight up on your keyboard, not slanted to the left) or double quotes, and numbers. If you enclose a number with quotes and perform mathematical operations on it, there will be no problems (Perl will treat the string like a number).
The comment character in Perl is #
. The semicolon ;
ends a line of code in Perl. It is possible to concatenate strings in Perl using a period between them, as in "War " . "and Peace";
(notice the space between the quote and War).
Online References