Official Guide to Programming with / Edition 1

Paperback (Print)
Used and New from Other Sellers
Used and New from Other Sellers
from $1.99
Usually ships in 1-2 business days
(Save 96%)
Other sellers (Paperback)
  • All (35) from $1.99   
  • New (10) from $19.12   
  • Used (25) from $1.99   


A complete guide to creating interactive Web pages using the Perl library from its creator.

Official Guide to Programming with contains all the information about found in Perl's online manual, but in a completely reorganized and greatly expanded format. It also includes valuable labor-saving tips and hints you won't find anywhere else. Featuring step-by-step instructions and complete source code, it shows you how to:
* Download, install, and configure
* Generate HTML documents on the fly
* Process fill-out forms and create multipage documents
* Perform script debugging and state maintenance
* Design interactive clickable image maps
* Store and process cookies
* Attach JavaScript and cascading style sheets to your documents
* Write state-maintaining scripts
* Modify and extend
* Tap the Comprehensive Perl Archive Network (CPAN).

Visit the companion Web site at

On the Web site you'll find:
* The most recent and all future revisions to the module
* All the source code examples from the book
* Online documentation for
* Links to CPAN and other Web-related software written by the author.

Visit our Web site at

Read More Show Less

Product Details

  • ISBN-13: 9780471247449
  • Publisher: Wiley
  • Publication date: 4/17/1998
  • Edition number: 1
  • Pages: 320
  • Sales rank: 1,387,932
  • Product dimensions: 9.25 (w) x 7.50 (h) x 0.68 (d)

Meet the Author

Dr. LINCOLN STEIN, a scientist at Cold Spring Harbor Laboratory, writes Web-based software for the human genome project. An undisputed expert on CGI and Perl, he writes a regular column for the Perl Journal as well as the "Webmaster's Domain" column for Web Techniques. He is also the author of the bestselling How to Set Up and Maintain a Web Site and Web Security: A Step-by-Step Reference Guide.

Read More Show Less

Read an Excerpt

Chapter 2: Basics

The easiest way to learn is to use it. This chapter shows you the basics by starting simple and gradually growing complex. Later chapters will teach the theory behind CGI scripting.

In order to run the examples in this chapter, you'll need to have:

1. Perl version 5.003 or higher If you don't have one or more of these things, see Chapter 1, Getting Started with, for help!

The examples in this chapter are available at this book's companion Web site at John Wiley & Sons. Load URL and follow the links to the source code examples.

Displaying a Plain Text File

The first four examples create plain text files on the fly and display them. They're as simple as CGI scripts get. Start your favorite text editor, and type in the following code:

# Script:
use CGI ':standard';
print header('text/plain'),
"Nothing to it!";
The top line of the file tells UNIX systems where to find the Perl executable file. In this and all subsequent examples, change this line to the correct path to Perl. Windows users can safely ignore this advice, since Windows uses file associations to associate documents with their applications.

Most Web servers require that CGI scripts be saved to a particular scripts directory. On UNIX systems, this directory is often named cgi-bin. On Windows systems, it may be called cgi-bin, scripts, or even cgi-standard. Identify this directory and save the file to it using the name If you are on a UNIX system, you will need to make the file executable (by typing chmod +x You should also make sure that the script is world readable (chmod o+w in UNIX, or by changing the access control list to allow reading by everyone in Windows NT).

First test the script from the command line. Type the following:

zorro> perl ""

If all goes well, the script will run and print out the following two lines of text:

Content-type: text/plain

Nothing to it!

We will cover the meaning of this text later.

If you get an error message, go back and confirm that Perl is installed correctly, that the PATH variable includes the location of the Perl executable, and that the CGI library is installed.

Now you are ready to run the script from the Web server. Open up a Web browser and point it at the URL of the script. This may be slightly different from server to server, but on most servers, you'll enter something similar to

The browser will ask the server to fetch your script's URL, the server will launch and run the script, and the script will return the document shown in Figure 2.1.

If the browser displays an error message, go back and check that the permissions of the script allow everyone to read and execute it. The Web server runs as an unprivileged user, and occasionally its privileges will deny the server permission to access a file that you can read under your own user account. If you still get an error, go to the Troubleshooting section later in this chapter.

Let's look at the script in detail:

use CGI ':standard';
This line loads the module, then imports its standard function definitions into your script. You can now use the standard CGI functions without prefixing them with the CGI:: namespace. In other words, you can refer to header( ) instead of CGI::header( ).
print header('text/plain'), This code is a Perl print( ) statement that prints out two strings. The first string is a call to the header( ) function, which returns a valid HTTP header. HTTP headers contain a variety of information that is meaningful to the Web server, the Web browser, or both. The important code here is the line that gives the browser the MIME type of the document to expect; in this case, text/plain. This results in the output of the header line "Content-type: text/plain."

The second string is the phrase "Nothing to it!" This becomes the contents of the document, often called the body. The document content is separated from the header by a blank line automatically provided by . . .

Read More Show Less

Table of Contents

Getting Started with Basics.

Advanced Tricks.


Reference Guide.



Read More Show Less


This is a complete guide to the Perl module, a package of routines that take the drudgery out of Perl CGI scripting and lets you concentrate on the fun part: creative programming. With you can create error-free HTML on the fly, write and process fill-out forms, design interactive clickable image maps, store and process cookies, handle file uploads, attach JavaScript and cascading style sheets to your documents, and maintain script state. With the help of other Perl modules, you can interface your CGI scripts to databases and other business applications. It works on almost all systems, including Windows, Macintosh, UNIX, OS/2 ,and even VMS. Best of all, is free. You will find it in the standard Perl 5.004 distribution. If you have a recent version of Perl on your system, is probably already installed and ready to use.
This book was born when I realized that the electronic version of the manual was getting out of hand. I wanted to add a tutorial section, more code examples, background information on the CGI protocol, and an expanded reference guide. However, at over 150K, the manual was already too long to read through while sitting in front of a computer screen, and it added noticeably to the size of the Perl distribution. This book contains all the information that you will find in the electronic manual, plus information that previously was only accessible to those courageous enough to mine the source code itself. I hope that those who use in their daily Web development work, will find the book a welcome supplement to the existing electronic resources. For those who have never heard of the CGI module, or have looked at it but are skeptical of labor-saving aids, I hope this book will convert them.
The book is divided into five chapters. Chapter 1 steps you through the process of downloading, installing it on your system, and configuring your Web server to use it. Chapters 2 and 3 are a combined tutorial and user's guide. Starting with simple scripts and working upwards in complexity, they take you through each of's main features. Working code examples show how each feature integrates into full CGI scripts, and may even give you ideas for your own applications. Chapter 2 covers the basics: generating HTML documents on the fly, processing fill-out forms, and creating multi-page documents. Chapter 3 covers advanced topics such as script debugging, state maintenance, cookies, frames, cascading style sheets, and fancy HTML formatting. Chapter 4 gives instructions for extending and modifying using Perl's object-oriented inheritance system. Chapter 5, the last chapter, is a complete reference guide to every function call, organized alphabetically. Appendix A lists the ten most frequently asked questions about Appendix B provides information about the companion Web site.
All the code examples contained within this book, the complete source distribution of, and any errata and updates can be found at this book's companion Web site at If you have enough space on your desk for both book and computer, you can follow along as you read. Each of the source code examples is fully functional. Read through the source code, then jump to the site to watch it run. Better yet, download the source code from the companion site and run it locally on your own server. That way, you can experiment with the code by changing it and seeing the effect it has on the resultant pages-or use the examples as templates on which to base your own scripts.
This book would not exist without the encouragement and understanding of Carol Long, my editor at John Wiley & Sons, and the efforts of Kathryn A. Malm, the assistant editor. My greatest thanks go out to the members of the Perl community, whose constant (and sometimes overwhelming) bug reports, feature suggestions, code patches, and cross-platform differences have made robust and feature-full. There are too many of you to list by name, but those who stand out from the rest (for their persistence, if nothing else!) include Tom Christiansen, Timothy Bunce, Andreas Koenig, Douglas MacEachern, Randal Schwartz, Gunther Birznieks, Keith Oborn, Robin Houston and Marco Dings. Thank you all for your tireless help.
Lincoln Stein
Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star


4 Star


3 Star


2 Star


1 Star


Your Rating:

Your Name: Create a Pen Name or

Barnes & Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation


  • - By submitting a review, you grant to Barnes & and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Terms of Use.
  • - Barnes & reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously

    If you find inappropriate content, please report it to Barnes & Noble
    Why is this product inappropriate?
    Comments (optional)