Programming in Perl
Spring 1998
Exam
Study Sheet
Note: The exam focuses on material
covered after the first test, but you shouldn't forget basic things, such
as Perl control structures, how to iterate through a hash, etc.
Regular Expressions
-
know what the match operator
does; what is the default scalar variable on which it operates?
-
know what the dot (.) matches
-
what is a character class?
be familiar with the predefined character classes?
-
be comfortable with using multipliers
to create regexes
-
given a regex, be able to tell me what
is stored in $&, $`, and $' after it is
applied
-
know the difference between greedy
and lazy evaluation
-
what is an anchor? how do we
match a pattern only at the beginning or end of a string? how do
we match a pattern only if another pattern appears after it (the second
pattern not being matched)?
-
have an idea of precedence and the
use of parentheses to group patterns
-
understand parentheses as memory; how
would we match a substring that contains four of the same characters (they
could be any character, but they must all be the same)? remember when ${grouping-pattern}
vs. \{grouping-pattern} is used
-
what does the pattern binding operator
do for us?
-
how can I replace all occurences of
a particular pattern in a string with another pattern using the substitution
operator?
-
understand that a scalar variable can
be interpolated into a string; remember that all regex pattern characters
interpolated will work properly
-
do not worry about the 'o' option to
the matching operator
-
do not worry about the quote escape
-
know how to split a line into
parts using a regex
-
know how to glue a line back together
using join from a list or array with a delimiter between fields
-
basically, be prepared to write some
simple regexes and indicate the results of applying certain operations
Filehandles
-
what is the naming convention for a
filehandle?
-
know how to open a file and
associate it with a filehandle
-
be aware of the different file modes
-- especially reading, writing, and appending
-
know how to close a file
-
be comfortable with handling error
conditions using die; know how to print out the most recent operating
system error
-
be able to write to or read from a
file using a filehandle
-
know how to rewind back to the beginning
of a file using seek
Functions
-
know how to define a subroutine
and how to return a value from it
-
know how to pass arguments to a subroutine
and be able to make use of @_ in a subroutine
-
what is the default "call by" in Perl
-- that is, are arguments passed in as aliases or copies?
-
be aware that a variable is by default
global unless declared with my in a subroutine
-
know how to use my to create
local variables and simulate "call by value"
-
do not worry about semiprivate variables
(those created using the keyword local)
-
basically, be able to write a subroutine
that takes arguments and returns some scalar or list value
Packages, Libraries, Modules, and
Pragmas
-
know what use strict; does
-
know how to bring a module into a Perl script via use
-
the only module you need to know anything about is CGI.pm
(see CGI section)
(Hard) References
-
how do you create a reference to an existing variable?
-
know how to create an array reference using the anonymous
array composer and how to create a hash reference using the anonymous
hash composer
-
be able to dereference a reference using $ (don't
worry about -> for dereferencing)
-
be comfortable with passing a reference as a parameter to
a subroutine and be able to dereference it and use its value in the routine
-
don't worry about passing references to filehandles
CGI
-
do not worry about emitting HTML source directly
-
you do not have to know how to create a form using HTML
-
be able to use param to retrieve data from a form
field
-
know how to use CGI.pm functions to emit HTML elements
and form widgets
-
be able to generate and process a form from a single CGI
script
-
know how to create a CGI query object and to invoke
CGI methods using the object
-
be comfortable with using named (verbose) calling sequences
to generate HTML form widgets
-
do not worry about locking files
-
do not worry about the Guestbook example from Learning
Perl, Chapter 19
Get in touch with me or one of the TAs if you have
any questions.
Good luck on the exam!