Basic Perl syntax

From WeBWorK_wiki
Revision as of 19:53, 3 March 2008 by Sam (talk | contribs) (New page: The PG Language is based on Perl. It helps to have a basic grasp of Perl before you start authoring PG problems. This article covers the minimum of Perl you need to know to work with PG. (...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The PG Language is based on Perl. It helps to have a basic grasp of Perl before you start authoring PG problems. This article covers the minimum of Perl you need to know to work with PG. (The following is excerpted from the perlintro manual page.)

Important changes from vanilla Perl

If you already know Perl, this is all you need to know:

Because backslashes have a special meaning within BEGIN_TEXT...END_TEXT blocks, backslashes are not used for their normal Perl meaning. Instead, ~~ (double-tilde):

Perl PG
print "Hello, $name\n";
print "Hello, $name~~n";
$aref = \@array;
$href = \%hash;
$sref = \$scalar;
$aref = ~@array;
$href = ~%hash;
$sref = ~$scalar;