Wordsmyth's Corner

Perl Primer - Chapter 1 - Introduction

by Linda Naughton

What is Perl?

Practical Extraction and Report Language
Pathologically Eclectic Rubbish Lister
(Actually it was originally just a name, not an acronym)

"The symbol of Perl has become the camel... Camels are there to get the job done despite all the difficulties, even when they look bad and smell worse and sometimes spit at you. Perl is a little like that." (Learning Perl)

Run-time Interpreted Language

Perl motto: "There's More Than One Way To Do It."

What is Perl Good For?

  • Quick and dirty programs.
  • Working with lists.
  • Working with text.
  • Working with files.
  • Web CGI

What is Perl *NOT* Good For?

  • Object Oriented Applications. (Perl objects are clunky.)
  • Bitwise manipulation or other advanced data storage (Perl by default hides those details)
  • Hiding source code. (Perl scripts are easily examined.)

Getting Help

Perl Directory (documents): www.perl.org
Comprehensive Perl Archive Network (modules): www.cpan.org

Perl's Hello World

#!/usr/bin/perl
print "Hello, world!\n";

The first line is a comment telling the system where to find the perl interpreter. On unix systems, this allows you to run a perl script without calling the interpreter explicitly. The location of your perl interpreter may vary. Not needed on Windows.

Running Perl

You need an interpreter. For Unix (and Mac OSX) systems, it's usually already installed. For Windows, get ActivePerl from activestate.com.

On Unix/OSX systems:

  1. Open a terminal window
  2. Create helloworld.pl with the contents above in your favorite text editor
  3. Type
    chmod +x helloworld.pl
    to make it executable
  4. Type
    ./helloworld.pl 
    to run it.

Note: Make sure the first line of the program has the correct path to your perl interpreter. You can usually find this by typing 'which perl'

On Windows systems:

  1. Create helloworld.pl with the contents above in your favorite text editor
  2. Make sure the perl interpreter is in your Windows path
  3. Open a command prompt window and change to the directory containing helloworld.pl
  4. Type
    perl helloworld.pl

Note: On Windows, you don't need the first line of the program specifying the perl interpreter. Technically you can run a perl program by double-clicking on it, but then you won't be able to see the output, so this is of limited usefulnes.
Next Chapter