Introduction to Perl

This document was written by CS 290W TA David Corcoran and was last modified

What is Perl?

Perl (Practical Extraction and Report Language) is a scripting language. It is unlike Java or C in that it is not compiled into byte code or machine language before it is run. Instead, it is interpreted at run time.

Perl was created by Larry Wall to ease string manipulation that would be tedious in many programming languages like C. For example, look at the following C code that is equivalent to a one line substring function in Perl. This grabs the substring in character string pcOldString beginning at location iBegin and continuing through iOffset characters and stores the result in pcNewString. For example, if pcOldString is "Boilermakers", iBegin is 3, and iOffset is 4, then pcNewString will be "lerm".

int CsubString(char *pcOldString, char *pcNewString, int iBegin, int iOffset) { int iRetVal; int step = 0; if ((iBegin+iOffset) > sizeof(pcOldString)) { iRetVal = 0; } else { for (int i=iBegin; i<iBegin+iOffset; i++) { pcNewString[step] = pcOldString[i]; step = step + 1; } pcNewString[step] = '\0'; iRetVal = 1; } return iRetVal; }


In Perl the previous operation would simply be:

$pcNewString = substr($pcOldString, $iBegin, $iOffset); Perl is used commonly to manipulate strings, search databases, and parse web forms through the Common Gateway Interface (CGI).

Availability: All flavors of Unix including BSD, Solaris, Linux, and AIX. There is even a Windows version.

Perl was originally written for Unix. WE WILL BE GRADING YOUR PROJECTS USING PERL FOR UNIX. Some features of Perl were left out and do not work properly on Windows versions of Perl. Feel free to use this, but make sure it works under Unix before turning in projects.

Perl is FREE. You may download it from: The Perl Developer Website.

There are several Perl manuals on the Web -- for example, Rex Swain's Perl Reference Guide.

Perl is distributed under the GNU public license and comes with source code. We will be using Perl version 5.004.

[ Back to Main ]