Programming in Perl
Spring 1998
Test 1
Study Sheet
Note: The regular expression material
will be part of the final; it will not appear on this test.
Introduction
-
know why we place #!/usr/local/bin/perl
at the beginning of a Perl script; what is the default action taken by
UNIX if we don't?
-
do not worry about using Perl at the
command line (that is, things like perl -ne 'print' test.dat which
doesn't run a script but rather executes the contents of the single quotes)
Literals
-
know how a single-quoted string treats
characters preceded by backslashes vs. how a double-quoted string treats
them
-
know how to use escape sequences to
alter the case of subsequent characters in a double quoted string
Scalar operators
-
know the difference between numeric
and string context and which operators invoke a particular context
-
know what the string operators
. and x do (and their precedence)
-
be able to convert a string to a number
as Perl would
Scalar Variables
-
what types of things can be stored
in a scalar variable?
-
what is the difference between $res
= ++$num; vs. $res = $num++; (for numeric data)
-
do not worry about ++ applied
to strings
-
what is variable interpolation?
-
know how read from STDIN in
scalar context
-
what does chomp do?
-
what does undef return in numeric
context? in string context?
Arrays
-
what is a list literal ?
-
be able to create a list using the list constructor operator
(..)
-
be able to create a list of strings using the quote word
function
-
know how to assign to an array using a list on the right-hand
side
-
know how to assign to a list of scalar variables from either
a list or array
-
understand what scalar context is vs. list context
-
know how to access an individual element of an array
-
what is an array slice? know how to use a slice
on the left- and right-hand side of an assignment
-
how can you get the size of an array? how can you get
the index of the last element of an array?
-
don't worry about negative array subscripts
-
don't worry about push, pop, shift,
and unshift (we didn't cover them in class)
-
be comfortable using sort
-
know how functions apply in scalar context and list context
(e.g., reverse and chomp)
-
know how to read an entire array at once from STDIN
-
what is the result of variable interpolating an array?
Control Structures
-
know the rules for determining true and false in Perl
-
be comfortable with using comparison and logical
operators to create conditional expressions
-
recall that there are two sets of comparison operators --
one for numbers and one for strings
-
be able to write nested if structures using elsif
-
know the difference between a while {} and a do
{} while
-
be comfortable using for loops
-
know how to use foreach; recall that this construct
returns an alias to each list element rather than a copy
Hashes
-
what is a key? what is a value? can two distinct
hash elements ((key,value) pairs) have the same key? can two distinct hash
elements have the same value?
-
know how to add elements to a hash and manipulate individual
values
-
what is used as the literal representation of a hash? know
how to create a hash from this representation
-
be able to create a hash using the "other comma" operator
(=>)
-
can a hash be variable interpolated? what is a shortcut
for printing the literal representation of a hash?
-
know how to iterate through a hash using control structures
and the following functions : keys, values, each;
what does each of these functions do?
-
how can you determine the size (number of elements) of a
hash?
-
know how to remove an element from a hash
-
what is a hash slice? be able to create or modify
a hash using a hash slice; be able to use a hash slice on the left-hand
side of an assignment
More on I/O
-
to which variable does the diamond operator (<>) automatically
make assignments?; know that a number of other Perl functions (e.g., chomp
and print) can implicitly use this variable
-
how does the diamond operator determine the files that it
will read from
-
what does the diamond operator do if no files are specified
on the command line with the name of the Perl script
-
be able to write code using the diamond operator
-
do not worry about printf
Get in touch with me or one of the TAs if you have
any questions.
Good luck on the test!