Introduction to Perl
Practical Extraction and Report Language
Pathologically Eclectic Rubbish Lister
Perl? perl? PERL?
The name of the language is "Perl".
Any expansion you may read was made up
after the fact. "PERL" is *never* correct.
Intro to Object Oriented Perl
Packages, Modules, Classes
Analogous to namespaces
provide a virtual "location" for subroutines and
ALL package variables are global variables
Default package is main
All other packages declared
Graphical User Interfaces
Event Driven Programming
In functional programming, what happens
when is determined (almost) entirely by the
programmer. The user generally has a
very limited number of options at any one
For each function, I will give its name and prototype.
prototype = number and type of arguments
ARRAY means an actual named array (i.e., variable
starting with @)
LIST means any list of elements (i.e., a list literal, a
Opening a File
To read from a file, create a filehandle.
another scalar variable.
prior to perl 5.6, had to use global barewords
by convention, all caps
open a file (for reading):
open my $fh, '<', 'myfile.txt';
Survey of Advanced Perl Topics
Standardized through the DBI module
not core module, but installed on CS system
Differing Database systems have their own DB
What is "CGI"?
Common Gateway Interface
A means of running an executable program
via the Web.
CGI is not a Perl-specific concept. Almost
is not Perl
any language can produce CGI programs
even C+ (gasp!)
However, Perl do
And how to use them effectively
how to use them effectively
If you need help with an assignment, or dont
understand a Perl feature, there are several
resources available, in a variety of formats:
Course Texts (Ca
semantically the same as C/C+
syntactically, slightly different.
if ($a > 0)cfw_
print "\$a is positive\n";
elsif ($a = 0)cfw_
print "\$a equals 0\n";
print "\$a is negative\n";
brackets are *req
More Regular Expressions
List vs. Scalar Context for m/
Last week, we said that m/ returns 'true' or 'false'
in scalar context. (really, 1 or ').
In list context, returns list of all the numeric
variables that have been captured ($1, $2, $3, etc)
Sometimes called "substitution"
In Perl, "Substitution" means something else
Replacing symbol/variable with its
meaning/value within string
meaning/value within a string