Cover image for CGI programming with Perl
CGI programming with Perl
Guelich, Scott.
Personal Author:
Second edition, expanded and updated.
Publication Information:
Beijing ; Cambridge [Mass.] : O'Reilly, [2000]

Physical Description:
xv, 451 pages : illustrations ; 24 cm
Format :


Call Number
Material Type
Home Location
Item Holds
QA76.73.P22 G84 2000 Adult Non-Fiction Central Closed Stacks

On Order



Programming on the Web today can involve any of several technologies, but the Common Gateway Interface (CGI) has held its ground as the most mature method--and one of the most powerful ones--of providing dynamic web content. CGI is a generic interface for calling external programs to crunch numbers, query databases, generate customized graphics, or perform any other server-side task. There was a time when CGI was the only game in town for server-side programming; today, although we have ASP, PHP, Java servlets, and ColdFusion (among others), CGI continues to be the most ubiquitous server-side technology on the Web.CGI programs can be written in any programming language, but Perl is by far the most popular language for CGI. Initially developed over a decade ago for text processing, Perl has evolved into a powerful object-oriented language, while retaining its simplicity of use. CGI programmers appreciate Perl's text manipulation features and its module, which gives a well-integrated object-oriented interface to practically all CGI-related tasks. While other languages might be more elegant or more efficient, Perl is still considered the primary language for CGI. CGI Programming with Perl, Second Edition, offers a comprehensive explanation of using CGI to serve dynamic web content. Based on the best-selling CGI Programming on the World Wide Web, this edition has been completely rewritten to demonstrate current techniques available with the module and the latest versions of Perl. The book starts at the beginning, by explaining how CGI works, and then moves swiftly into the subtle details of developing CGI programs.Topics include:

Incorporating JavaScript for form validation Controlling browser caching Making CGI scripts secure in Perl Working with databases Creating simple search engines Maintaining state between multiple sessions Generating graphics dynamically Improving performance of your CGI scripts

Author Notes

Scott Guelich graduated from Oberlin College in 1993 with a philosophy degree and decided to "only take a few years off" before continuing with graduate school. Unable to find any listing for "Philosopher Wanted" in the classifieds, and having done some programming while growing up, he quickly found himself working with computers. He discovered the Internet the following year and Perl the year after that. Scott has been a web developer for the past few years and currently contracts in the San Francisco Bay Area. He enjoys taijiquan, mountain biking, wind surfing, skiing, and anything that gets him outside and closer to nature. Despite the hours he spends working online, Scott is actually a closet Luddite who doesn't own a television, hasn't bought a cell phone, and still intends to make it to graduate school . . . some day.

Shishir Gundavaram graduated from Boston University with a BS in Biomedical Engineering in May of 1995. For his undergraduate thesis, he developed a Windows application for the Motor Unit Lab of the NeuroMuscular Research Center that allowed researchers to acquire and analyze muscle force output from patients to indirectly observe the electrical activity of muscles. He was the sole author of CGI Programming on the World Wide Web, published by O'Reilly & Associates, Inc., in 1996.

Gunther Birznieks is currently the chief technology officer for, best known for its open source web programming archives and online tutorials in a variety of subjects related to web programming (Perl, CGI, Java). Before this, Gunther did web programming and infrastructure for the Human Genome Project. Most recently, he was an associate director at Barclays Capital where he had been the global head of web engineering.

Table of Contents

Prefacep. ix
1. Getting Startedp. 1
Historyp. 1
Introduction to CGIp. 2
Alternative Technologiesp. 8
Web Server Configurationp. 11
2. The Hypertext Transport Protocolp. 16
URLsp. 17
HTTPp. 22
Browser Requestsp. 25
Server Responsesp. 32
Proxiesp. 36
Content Negotiationp. 39
Summaryp. 41
3. The Common Gateway Interfacep. 42
The CGI Environmentp. 43
Environment Variablesp. 45
CGI Outputp. 51
Examplesp. 60
4. Forms and CGIp. 65
Sending Data to the Serverp. 65
Form Tagsp. 67
Decoding Form Inputp. 80
5. CGI.pmp. 84
Overviewp. 85
Handling Input with CGI.pmp. 89
Generating Output with CGI.pmp. 103
Alternatives for Generating Outputp. 110
Handling Errorsp. 114
6. HTML Templatesp. 121
Reasons for Using Templatesp. 121
Server Side Includesp. 123
HTML:: Templatep. 132
Embperlp. 140
Masonp. 161
7. JavaScriptp. 163
Backgroundp. 163
Formsp. 165
Data Exchangep. 176
Bookmarkletsp. 186
8. Securityp. 194
The Importance of Web Securityp. 194
Handling User Inputp. 196
Encryptionp. 204
Perl's Taint Modep. 206
Data Storagep. 210
Summaryp. 213
9. Sending Emailp. 214
Securityp. 214
Email Addressesp. 216
Structure of Internet Emailp. 221
sendmailp. 222
mailx and mailp. 226
Perl Mailersp. 226
procmailp. 228
10. Data Persistencep. 231
Text Filesp. 231
DBM Filesp. 239
Introduction to SQLp. 244
DBIp. 247
11. Maintaining Statep. 264
Query Strings and Extra Path Informationp. 267
Hidden Fieldsp. 273
Client-Side Cookiesp. 286
12. Searching the Web Serverp. 293
Searching One by Onep. 293
Searching One by One, Take Twop. 297
Inverted Index Searchp. 301
13. Creating Graphics on the Flyp. 311
File Formatsp. 311
Outputting Image Datap. 314
Generating PNGs with GDp. 317
Additional GD Modulesp. 322
PerlMagickp. 331
14. Middleware and XMLp. 338
Communicating with Other Serversp. 339
An Introduction to XMLp. 342
Document Type Definitionp. 345
Writing an XML Parserp. 347
CGI Gateway to XML Middlewarep. 348
15. Debugging CGI Applicationsp. 357
Common Errorsp. 357
Perl Coding Techniquesp. 360
Debugging Toolsp. 367
16. Guidelines for Better CGI Applicationsp. 374
Architectural Guidelinesp. 374
Coding Guidelinesp. 382
17. Efficiency and Optimizationp. 385
Basic Perl Tips, Top Tenp. 386
FastCGIp. 395
mod_perlp. 397
A. Works Cited and Further Readingp. 403
B. Perl Modulesp. 407
Indexp. 411