Chatting Up CGI.pm
By Randal L. Schwartz
Web-chat scripts resemble Internet Relay Chat, but with far fewer bells and whistles: Several people go to a particular URL at the same time, type messages into a form field, press Submit, and then get to see what the others said at the same time. Kind of like a really fast-moving guest book that keeps only the 32 most recent entries. Some people are into this.
I, as you well know, am into the all-singing, all-dancing, gotta-have-it CGI.pm module -- always looking for ways to show off its fantastic features. Take its save method, for example, which allows you to save structured data into a flat text file to be processed later. To demonstrate this feature and illustrate how to flock() a datafile and generate HTML on the fly, I've hacked out a little Web-chat script. Stick it somewhere, and you can talk with a friend, or make friends.
Let me state up front, however, that this script is not meant to be used as-is. It merely illustrates some technology around the CGI.pm module, saving and restoring queries, and how to use flock().
The Program
Listing One presents my little toy Web-chat script. Lines 1 and 2 enable taint checks, warnings, and appropriate compiler and runtime restrictions. Line 4 pulls in the CGI.pm module, and defines the standard useful set of form-access and HTML-generation methods.<>