CGIs and Perl scripts

We have seen previously what are CGIs and an introduction to Perl scripts. This page puts the two together. This is, however, a very brief overview of the subject emphasizing the process rather than the details of each step of the process. I will use Netscape and the Web Teach Server for the practical examples, but most web servers behave similarly.


The request for a CGI is initiated by a web browser (client) when a user selects a link containing an URL especially coded for this purpose. The URL is comprised of six parts:

  1. protocol (http, ftp, etc)
  2. hostname (either a FQDN or IP number)
  3. port (if not the default 80 for HTTP)
  4. path (the location of the page/CGI on the host)
  5. parameters (like size, etc, not required)
  6. argument string (the input to a CGI, if any, preceded by a ? mark.)

The server only sees the last three parts, the first three let the client contact the server. The server replies to the client with header lines and content. The content is whatever the page requested by the client has.The required header lines are:

In addition with each request the server also receives environment variables that are not request-specific. What the server does with all this information depends upon the server and has a bearing on the CGI programming. As more the server does, less the programmer has to do, and vice-versa.

From this point on we can only discuss CGIs regarding a specific server and a given CGI programming language. In this page we will concentrate in the Netscape (and Apache) web server behavior and the use of Perl scripts to create CGIS, as pointed out before.

CGI support for Perl

A CGI Perl script example

You can see here an example of a CGI created in Perl for the Pebble Server in order to collect bug reports and suggestions regarding the server (this script was adapted from the documentation from the WebSite).

You can see the code for the Perl script here. Lets walk through the script and understand how a CGI works.

This page is maintained by Al Bento who can be reached at This page was last updated on March 5, 2003. Although we will attempt to keep this information accurate, we can not guarantee the accuracy of the information provided.