Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Running Perl Programs

April 26, 1999

A Perl program, as we'll soon see, is a text file containing Perl code. There are several ways to launch a Perl program, depending on your needs and the operating system in which you develop.

Typically, you'll see that many Perl programs found on the net or in tutorials begin with the line:

#!/usr/bin/perl

The above line is actually intended for UNIX systems -- other operating systems will simply ignore it. However, because UNIX is typically considered the de facto platform for Perl, many Perl programs include this line. It tells UNIX where to find the Perl program; the path /usr/bin/perl is a common location for UNIX-based Perl installations. If you are working in a UNIX environment, it is important that this first line point to the correct location for Perl on your particular system; alternatives may look like, for example:

#!/usr/local/bin/perl
#!/usr/bin/perl5

In either UNIX or Windows, if the perl program is in your search path you can also run a Perl program simply with the command line:

perl programName

Windows users might also use associations to run Perl scripts. Windows associations assign a particular program to run when a filename with a particular extension is launched. Thus, you can associate the perl executable with filenames ending, for example, in .plx or .pl. ActiveState's Perl installation will setup such an association for you. You can then launch Perl programs by simply double-clicking them from the desktop.

Keep in mind that for Web developers, many Perl programs will be launched in the context of CGI. We'll talk more about CGI later, but for now you should understand that using Perl programs for CGI involves a combination of the Web server's configuration and the above methods of launching Perl programs.

 

Show me the Perl: Greetings

A Perl script can be a very simple thing. The following program does only one thing: outputs the message "Welcome to Currency Central".

#!/usr/bin/perl

print "Welcome to Currency Central\n";

What could be simpler? The only bits in need of explanation here are two: first, note the \n. The backward slash (\) indicates an escape sequence, which refers to a special character that cannot easily be typed on the keyboard. The \n escape sequence represents a newline, causing there to be a linefeed in the output following the word "Central".

Also notice the semicolon which represents the end of a Perl statement. Not all Perl statements require semicolons at the end, but it is good practice, since omitting a semicolon where one is required will definitely result in a program error.

It is always a good idea to add comments to your program code, which make it easy to remember what a particular line does. Sometimes this is not obvious by simply reading the line of code. Comments in Perl begin with a pound sign (#), and continue to the end of that line.

#!/usr/bin/perl

#Output welcome message
print "Welcome to Currency Central\n";

Simple enough, but this isn't exactly an impressive display of Perl power. Programming languages derive much of their power from the use of variables. Almost every developer has encountered variables in one scenario or another -- a variable is simply a "container" or label which possesses a certain value. We begin our study of Perl in earnest with a look at variables in Perl.

Getting Perl
The Perl You Need to Know
Perl Variables: Scalars


Up to => Home / Authoring / Languages / Perl / PerlfortheWeb




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers