Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Perl CGl Programming: No experience required.
(Publisher: Sybex, Inc.)
Author(s): Erik Strom
ISBN: 0782121578
Publication Date: 11/01/97

Bookmark It

Search this book:
 
Previous Table of Contents Next


Perl and the World Wide Web

Perl has become popular for Web work because in most of its incarnations it is an interpreted language, like the first versions of BASIC, rather than a compiled language, such as C or C++. However, this isn’t strictly true, because Perl compilers are available from many sources, just as there are many C interpreters to be had. The essential difference between a compiled and interpreted application is that a compiled program has been translated into the machine language of the computer on which it will run by another program called a compiler. The translated, or compiled, file will run all by itself. An interpreted program, on the other hand, is actually translated and run on the fly by a program called an interpreter.

Compiled programs, because they consist of machine-language instructions, generally run faster. But for the same reason, they are not portable from one computer platform to another. Code compiled for a Sun box or a Macintosh won’t run on an Intel-based PC because the different processors that power these machines all speak radically different tongues. Your program would have to be recompiled for the target machine before it would work. It may even have to be rewritten.

There are no such restrictions on interpreted Perl code. All you need is some version of the Perl interpreter—called perl—on the target computer. Perl interpreters have been written for every popular computer platform, from Sun to Alpha to Apple to Intel and more, and with very few exceptions your Perl programs should transport unchanged into every environment.

This feature won’t sound very important to novice programmers. However, porting C code even between the different flavors of UNIX is an art that not many people have the patience or skill to do full time. It is tedious, difficult, and time-consuming. The capability to develop and test code on one computer and then simply drop it into another, as you can do with Perl, is a boon cherished by all professional programmers.

Perl programs are not compiled, which is why we refer to them as scripts. Like shell scripts in UNIX or batch and command files on MS-DOS and Windows NT, Perl programs are just text files that run through an application to process their commands.

However, make no mistake about it: Perl programs are just that—programs, with all the power and versatility the word implies. If you’ve never written a line of code in your life, Perl will forever spoil you against the more traditional programming languages. If you are a programmer but this is your introduction to Perl, you will find yourself using it more and more as your familiarity with it increases, because it makes things so easy.

For the nuts and bolts of Web site processing, administration, and maintenance, tedious system chores that should always be hidden from users, in addition to the creation of truly dynamic Web pages, Perl can’t be beat.

Building a Perl Script

Now that you have a little background, you’re going to write your first Perl program. It’s a simple example that gives you the basic idea of how a Perl script is written and run. All of our subsequent examples will build on this one.

“Hello World” probably seems kind of dumb, but those of us who have been programming for a while have a soft spot for this snippet of code. It’s the first programming example given in the monumental C Programming Language by Brian Kernighan and Dennis Ritchie, published in 1976. Many programmers cut their teeth on this work; forgive us, please, if we remember it fondly.

Using Existing Perl Scripts

Perl scripts are simply text files that you can create using your favorite text editor. Perl is the language of choice for Web developers these days because of its ease of use on UNIX machines. Its popularity, which may be one reason why you bought this book, also has other benefits: for one thing, a huge body of existing code out there in the ether. Most of it is free, which means you can simply drop it into your Web server and run it, regardless of the operating system that powers your computer. Most of that code was written, tested, and debugged by UNIX programmers who had their own Web sites to maintain. You can find lots of stuff in USENET—go to comp.lang.perl. Or try one of the Web search engines such as Yahoo!.

So it makes sense for you to be running Perl on your Web site, if only from the standpoint of the effort you want to put into writing software. If you have a task to perform and someone else has already written the code to perform it—and has no compunctions at all about you using it—then why shouldn’t you avoid reinventing wheels?


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.