CGI and Perl

What Forms Cannot Provide

You've just seen how forms can become a very valuable addition to your Web site. I have described the HTML form as a potential cross-platform, simple user interface. There are still some features that are missing that prevent it from replacing other traditional user interfaces. HTTP requests and responses are pretty much atomic in nature. This means that a persistent communication channel between the browser and the server is not directly supported. The protocol was intended as a means of requesting and serving small files over the Net to produce fairly rich graphical content. The lack of a persistent server-side state is obvious. This problem will be examined later on in Chapter 16, "Advanced CGI/HTML."

Another problem lies in the fact that the HTML form is a static entity once it reaches the browser. This means that it cannot handle certain user events that most user interface programmers probably take for granted. For example, suppose you want to enable or disable a field, depending on whether or not something is typed into a text field. This is common practice for most graphical user interfaces, yet it is not possible using HTML forms. There are alternatives for doing this kind of thing. For example, Java provides this type of client-side executable capability. Embedding a Java applet within your Web page can give you some more powerful capability. However, this extra capability does not come free. You would have to learn how to program with the Java AWT (applet window toolkit), and the transmission time for downloading the applet can be higher.


Now that you have learned all about HTML forms and how they can be generated with the CGI::Form module, you are ready to find out about the other, more powerful aspect of this module: its capability to simplify the processing of the form.

Putting It All Together

  • HTTP Transactions
  • Perl5 and the WWW Libraries in Action
  • Example 1: Creating Forms with
  • Example 2: Open a New Browser Window
  • Example 3: Upload a File to the Server
  • Example 4: Using CGI::Carp to Debug Scripts
  • Using the HTTP::Request Module Directly

The first step to mastering CGI programming and creating useful and dynamic programs is understanding what goes on when your CGI script is run. The transaction that occurs between the Web server and the browser before your script is run--and the data that is transferred back and forth during this transaction--is the only input your script has. Thus understanding exactly how something occurs and what occurs during this transaction is crucial.

After looking at all that happens during the transaction, we'll focus on how Perl5 modular libraries such as and the libwww modules can be used to greatly simplify and enhance
programming CGI scripts. and the libwww modules provide simple APIs (applications programming interfaces) which allow you to supply a few simple arguments to a supported Web-related function. The module then generates appropriate HTML output for you. Tasks such as creating HTML forms, imagemaps, and headers are just a few of the tasks enhanced by using these Perl5 modules in your program.