Getting Started

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

Your Perl programs will be run as APPLICATIONS, not as APPLETS. They can be in your www folder (or some sub-folder) of that. You can create them anywhere and ftp them to your career account.

You can name your Perl script anything you want. It is common to add the extension .pl to your Perl file. So your first Perl program might be named helloworld.pl. You will also need to issue the following command to tell the operating system that this script is executable.

This will make your script executable by the operating system. To run your program, simply type its name helloworld.pl and press ENTER.

A Perl script must know where to find the Perl interpreter. To do this, it is necessary to include one line at the beginning of every program you write in Perl.

This tells the operating system where to find the Perl interpreter. It is located in the folder (directory) /usr/local/bin/ on mentor, expert, and icdweb.

Hello, World

Our first Perl program, the notorious "Hello, World", will only require two lines of code:

#!/usr/local/bin/perl print "Hello, World! \n"; The first thing you should notice is there is no main function, init method, or start function. Perl is not structured like other programming languages. It does not require a main function. It merely finds the first line of code and begins executing it.

You will also notice the print function. This function does exactly what it says it is doing. It prints the text following it in quotes. The \n tells it to start a new line when it is finished printing that line.

Each line of code in Perl (but not the first line which is information to the operating system) is ended with a semicolon. You should be used to this notation from JavaScript and Java.

[ Back to Main ]