Perl Lesson 1
Wednesday, August 30, 2006
1. Obtain a copy of Perl
• For Windows
(a) Downloading Perl:
i. Go to: http://www.activestate.com/Products/Download/
ii. On the left is a listing of diﬀerent versions of ActivePerl
188.8.131.527 (or whatever the most current is) – scroll down
a bit until you ﬁnd the Windows part - click on MSI (which
iii. Windows will ask if you want to run this ﬁle or save it.
Choose to run it.
iv. Windows might inform you that the publisher could not ver-
ify this software. As far as I know, there are no viruses, so
click on Run.
v. The installer should be pretty self-explanatory, and it should
put everything where it belongs (C:Perl\ is the default, I
think). By default, it will add C:\Perl\ to your path - do
not change this. (What this does is to make sure that you
can run Perl from any directory you happen to be in.)
(b) Running Perl:
i. Open up a Windows Command Prompt: this is typically
located at: Start → (All) Programs → Accessories → Com-
mand Prompt. This will just be a black command line inter-
face, and you’ll probably be in a directory like C:\WINDOWS.
ii. Type perl -v to verify that you have Perl installed.
iii. Move to the directory where you have your perl ﬁles (see
below): in the command prompt, you move from directory
to directory by the cd command. Some examples:
– To move down a directory:
– To move up a directory:
– To move to the root directory:
– To specify the complete ”path name”:
iv. Once you’re in the appropriate directory, you can run perl
by typing perl <filename.pl> ... this runs a perl ﬁle (de-
(c) Writing Perl ﬁles:
i. Go to whatever directory you want to store Perl ﬁles in.
ii. Open up Notepad - or some other plain text editor (do not
use Word for this).
iii. Write your Perl code
iv. Save the ﬁle, with a “.pl” extension, e.g. “myﬁle.pl” ... now
you should be able to run the Perl ﬁle, as described above.
• Macs (or Unix/Linux)
(a) Perl should already come installed. If not, you can download
from the same activestate site as above. Under Applications →
Utilities, click on Terminal
– Type perl -v to make sure it’s there
(b) Running the program is the same as in Windows. See (1bii) for
tips on moving around the directory structure—note, though,
that with the Mac terminal, you’ll use ’/’ instead of ’\’
(c) To write ﬁles, use something like TextEdit or pico (available
on terminal windows). Otherwise, the tips are the same as for
2. Save the following program to a ﬁle and run it, to verify that everything
print "Hello world!";
3. Skim over the tutorial (up through the Split section), to get a feel for what
Perl is about, at: