[an error occurred while processing this directive] [an error occurred while processing this directive]

CUSTOM CGI SCRIPTING WITH PERL

Kevin Hanegan

Welcome

This is the companion Web site for Custom CGI Scripting with Perl. Here you will find all the source code, links to related CGI and Perl information, links to any software you may need, as well as updates to the material in the book. You can use this site to find necessary information, link to many CGI script repositories, and get the latest news on Perl. This site will also include a Bulletin Board so developers can post questions they may have. If you're interested purchasing the book, visit one of the following Web sites: Amazon, Barnes and Noble, or John Wiley & Sons.

Table of Contents

Part I: Getting Started

1. Overview of CGI
2. The CGI Framework
3. Installing a CGI Script

Part II: Perl Building Blocks

4. Introduction to Perl
5. Using the Print Statement
6. Using Variables
7. Statements and Conditionals
8. Subroutines
9. Pattern Matching
10. File Input and Output
11. Working with HTML Forms
12. Using Databases
13. Interacting with your Operating System

Part III: Advanced Perl Techniques

14. Error Handling
15. Debugging Your Perl script
16. Securing Your Perl script

Part IV: Putting It All Together

17. Planning Your Perl script
18. Email Response Form
19. Guestbook
20. Flat-file Database

Appendices

A. Request and Response Headers
B. Server Status Codes
C. Basic Unix Commands
D. Environment Variables
E. Perl Special Variables
F. Perl Built-in Functions
G. SQL Commands
H. Perl Quick Reference

Applications Mentioned in the Book

WS FTP LE - WS-FTP LE is a great application that allows remote file edits, chmods on UNIX boxes and file moves.
Dos2Unix Application - Windows and Unix systems use different methods to identify end-of-line information in text files. Windows uses a carriage return/linefeed pair (CR/LF) and Unix only uses the LF character. DOS2UNIX.EXE is a small utility that converts MS-DOS text files to Unix format, by stripping any CR or end-of-file (Ctrl-Z) characters from the data.

Free Web Servers

Savant Web Server - Savant is a freeware web server that runs on Windows 95, 98, NT, and 2000, turning any desktop computer into a powerful web server. Designed to be fast, secure, and efficient, Savant is the choice of thousands of professional and amateur webmasters worldwide.
Tiny Web Server - TinyWeb is intended to be a simple Win32 daemon for regular (TCP/http) and secure (SSL/https) web servers that will allow you to test your CGI scripts on your desktop. TinyWeb is extremely small (executable file size is 49K), simple (no any configuration except command line) and fast (consumes as little system memory and CPU resources as possible). TinyWeb installs in minutes and maintains a low-memory profile.
WebReflex Web Server Facilities - Another free Web server that will allow you to test your Perl scripts locally.

Additional CGI Tools

Perl Scripting Tool - was originally intended as a replacement for Windows' Notepad, which until now has been the editor of choice for Win32 PERL Programmers. While Notepad is usually sufficient there has long been the need for something with 'just a little more'. Features include: the ability to right click on your script and get a menu of the most useful functions; the ability to find matching brackets and go to line numbers; a built-In HTM2PERL utility; the ability to parse HTML; a subroutine library; an optional auto tab/indent; definable color syntax checking; an enhanced dual clipboard; a syntax checker; the ability to script quickly with the code wizard; user defined shortcut keys; and a scratch pad.
CGI Script Editor (free) - A program that is designed to help you create cgi-scripts. It is essentially a simple text editor, with quite a few enhancements to make it easier for you to make powerful and error-free scripts. It is better that using a simple text editor.
Visual Perl Editor ($29) - Helps create CGI scripts in Perl, offline in Windows, visually. The program has two panels, one to edit the script and another that previews the CGI in an internal web browser. Also integrated testing for errors or running normally. It supports code-templates to add to your script, a Query editor to easily create Querys for a GET method, HTML Editor, URL encoder, bookmarks, FTP uploader, unlimited sized scripts. Also directions on how to run CGI Perl scripts in windows offline.
Website Explorer 1.5 ($19.95) - Website Explorer is a graphical website tool that allows you to remotely Explore, View, Edit, Delete, Chmode, test CGI Scripts and Upload files to your website. Right from your own browser.
Perl modules - CPAN contains the collected wisdom of the entire Perl community: hundreds of Perl utilities, several books' worth of documentation, and the entire Perl distribution. If it's written in Perl, and it's helpful and free, it's in CPAN.
Perl interpreter - This site will allow you to download the latest Perl interpreter for a variety of operating systems.

Code from the Book

Chapter 3
3.1 - Displaying Environment Variables
Chapter 5
5.1 - Return a Web page that says Hello World using print
5.2 - Return a Web page that says Hello World using print and contains \n characters at the end of each line
5.3 - Return a Web page that says Hello World using print and contains \n and
characters at the end of each line
5.4 - Return a Web page that says Hello World using print escaping some special characters
5.5 - Return a Web page that says Hello World using print escaping some special characters used in a table
5.6 - Return a Web page using the here printing method to return a table
5.7 - Return a Web page using qq to return a table
Chapter 6
6.1 - Return a Web page with the current time stored as a variable
Chapter 7
7.1 - Return a Web page to loop through ten years and print the amount in a given account each year
Chapter 9
9.1 - Retrieves a string from an HTML form and removes any digits from it
Chapter 18
18.1 - EmailResponse.pl
18.2 - Form for EmailResponse.pl
Chapter 19
19.1 - Guestbook.pl
19.2 - Form for Guestbook.pl
19.3 - Guestbook.pl (Advanced)
19.4 - Guestbook.html
Chapter 20
20.1 - Addentry.html
20.2 - Addentry.pl
20.3 - SeacrhDB.html
20.4 - SeacrhDB.pl
20.5 - DeleteDB.pl

Resources

CGI - Common Gateway Interface - Contains links to specs and documentation, discussion groups, and next-generation APIs.
CGI Specification at NCSA - From introduction to in-depth details.
CGI Programming FAQ - The author updates this FAQ as new questions are submitted. It covers quite a wide range of topics from basics to HTTP and troubleshooting scripts.
CGI Script FAQ - A practical rather than an academic list of questions and answers.
Perl FAQ - Frequently asked questions about PERL.
CGI Programming 101 - Free online course written by Jacqueline Hamilton. Five lessons already exists and more will eventually be posted.
Perl Tutorial -Self-paced tutorial on the basics of Perl. The reader learns by writing a script called mailform.
CGI Resources - Excellent source for tutorials, scripts archives and demonstrations.
Perl for CGI Quick Reference
This document lists all the basic syntax and commands needed to write basic CGI scripts using forms. Each section is explained with the use of an example.
The CGI Resource Index - An outstanding collection of resources, links, tutorials, and scripts, from the author of Matt's Script Archive.
The WDVL: CGI - More resources on CGI.
Yahoo�s CGI Index - A continually updated collection of links related to CGI programming.
The Perl Language Home Page - Overview, software and more excellent resources.
Matt�s Script Archive
The Scripts Home
Jeff�s Script Archive
Mike�s Scripts
Selena Sol�s CGI Script Archive
Cover

ISBN 0471395978
352 pages
January 2000

Wiley Computer Publishing
Timely. Practical. Reliable.