Perl Lesson 1 by hcw25539


									                           Perl Lesson 1
                            Linguistics 362
                   Wednesday, August 30, 2006

1. Obtain a copy of Perl

     • For Windows
       (a) Downloading Perl:
             i. Go to:
            ii. On the left is a listing of different versions of ActivePerl
       (or whatever the most current is) – scroll down
                a bit until you find the Windows part - click on MSI (which
                is 12.8MB).
           iii. Windows will ask if you want to run this file 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 files (see
                below): in the command prompt, you move from directory
                to directory by the cd command. Some examples:
                – To move down a directory:
                       C:\WINDOWS>cd temp
                – To move up a directory:

                       C:\WINDOWS\temp>cd ..
                 – To move to the root directory:
                       C:\WINDOWS\temp>cd \
                 – To specify the complete ”path name”:
                       C:\WINDOWS\temp>cd \MyDocuments\greatclasses\nlp\perl
            iv. Once you’re in the appropriate directory, you can run perl
                 by typing perl <> ... this runs a perl file (de-
                 scribed next)
        (c) Writing Perl files:
              i. Go to whatever directory you want to store Perl files 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 file, with a “.pl” extension, e.g. “” ... now
                 you should be able to run the Perl file, 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 files, 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 file 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:



To top