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


Skill 1
Introducing Perl and CGI

  Why Perl?
  Perl’s ancient history
  Building a Perl script
  Variables, scalars, and lists in Perl
  Perl and the Common Gateway Interface
  CGI programming languages

The Internet has become—perhaps arguably—the most important communication medium in the world. There is virtually no argument, however, about the World Wide Web. It is the Internet’s most important channel of communication. If you want to deal with the Net, pretty soon you’ll have to deal with the Web.

You’ll learn about one of the most important aspects of the Web in this book. The Common Gateway Interface (CGI) and applications written in the Perl programming language give you the tools to create dynamic, informative Web pages, with which you can fashion a Web site that your visitors will find truly useful and worth revisiting.

A good Web site is not just a collection of pretty pictures. It has to do something. With Perl and CGI, you can make it do just that.

Why Perl?

A Web page is a text document that is formatted with a set of commands—a programming language, if you will—called the Hypertext Markup Language, or HTML. The name is descriptive: HTML is a “markup” language; that is, it controls the way a document looks. HTML instructions tell a Web browser, such as Netscape’s Navigator or Microsoft’s Internet Explorer, how it should go about displaying the page on-screen. But HTML all by itself has practically no facilities for making a Web page do things. You have to rely on other means for that.

The Perl programming language is hands-down the most popular method of making a Web page “do” something, mainly because Perl is freely available and will run on every computer platform that can host a Web server. Coupled with the Common Gateway Interface (CGI), Perl is used on the vast majority of Web sites to create Web pages that have to do more than sit there and look pretty.

There are a couple of other tools you can use to create a dynamic Web page:

  Java
  Proprietary languages

The following sections will look at each of them.

Java

Java, which was originally invented by Sun Microsystems to control toasters, is a popular and highly touted method for making interactive Web pages these days. As a programming language, Java is a very rich resource, one that will allow you to do almost anything you desire with your page. However, not all Web browsers support Java, so by including an applet written in that language in your page, you are necessarily excluding an entire class of visitors.


TIP:  An applet in Java is a program that is run by the Web browser, if the browser is capable of running it (many Web browsers aren’t).

To work properly, Java depends on the browser software that your visitors use. If the browser supports Java, your applets work. If not, and you are a kind Webmaster, your visitors will get a message telling them essentially to buy another browser. If you are unkind, they will get either a blank screen or some wonderfully obscure HTTP error message that, if nothing else, will ensure that they never return to your Web page again.

Proprietary Languages

Along the same lines as Java are the proprietary packages, notably Visual Basic Script from Microsoft and Netscape’s JavaScript.


TIP:  Proprietary software packages usually target a specific hardware and/or software platform. They won’t work with everything.

Visual Basic Script is, of course, based on Visual Basic, Microsoft’s heavily Windows-laden version of the BASIC programming language. JavaScript is an interpreted flavor of Java, which means that the Web browser interprets and executes each line in the script. While the intent of both—essentially extending HTML to make the Web page itself more dynamic—probably is laudable, neither will run on any but the newer browsers from both companies, because the older browsers were written before these tools existed.

They’re slick, yes. By taking advantage of a specific platform, the proprietary tools can run faster and do more than a generic package that is intended to run on all platforms. But they don’t allow you to accommodate every visitor to your site because not all visitors will have the hardware or software that the proprietary tools target (see Figure 1.1). Not all visitors will be using Intel-based PCs, nor will all visitors be running a version of Netscape or Internet Explorer, or Windows 95 or NT.


Figure 1.1:  Proprietary languages can exclude visitors to your Web site.

Some visitors may not even be able to display graphics. But all of them need to be considered when setting up a site.


NOTE:  The proprietary methods extend HTML by creating programs that run on a visitor’s computer, rather than at your site on your Web server. As a result, they depend totally on the computer and software the visitor is using.

CGI

Long before Java, there was the Common Gateway Interface, CGI for short. We’ll explain CGI in detail when we tackle Skill 2, but for now let’s just say that it’s the most common method for passing information from an HTML document to a program that can process the information. CGI doesn’t care what browser you’re using; even non-graphical Lynx-type software will work.

Unlike Java and its more proprietary cousins, CGI is not a programming language, nor does it load itself onto the visitor’s machine to run. CGI is, as its name spells out, an interface, a set of rules. It resides on the Web-server computer, providing a way for the page to communicate in a rough fashion with the server. CGI allows you to write programs to deal with the page in any language—including Perl.


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.