Beginning CGI Programming with Perl


I covered a lot of territory in this Tutorial, and a lot of it still might seem confusing. Don’t worry-the purpose of this Tutorial is to get you thinking about the concepts of CGI programming. The remainder of these tutorials explains these concepts in detail. In this Tutorial, you learned that CGI programming is a lot more than just another programming language. It is really a programming paradigm-something that defines how you program and not what you program.

CGI programming is not a single language or application; it is making applications work in that wonderful WWW environment. In this Tutorial, you learned about the three main keys to your CGI program: HTML, HTTP, and your server. Each of these impacts how your program is structured to satisfy the needs of each application. You also learned about the structure of your server and where to find the different parts of your server directories.

Finally, you learned some of the common CGI programming mistakes to avoid as you begin to build your own CGI program applications.


Q Where should I put my CGI programs?
A Ultimately, your System Administrator or Webmaster has control over where you can install your CGI program. If you are on an ncSA server, you can create and run your CGI program from any directory. It’s usually a good idea to keep your CGI programs in a common directory, however. That way, you can find a program when you need to modify it. A lot of systems create a single directory called the cgi-bin directory. If your server is set up this way, you might need to have your Webmaster install each CGI program you create. Because this is such a time-consuming process, however, you usually can be added to the groupname that has privileges to write to the cgi-bin directory. Check with your server’s System Administrator.
Q Are CGI programs only interface programs?
A There are absolutely no restrictions on what your CGI program can be. The only limitation on a CGI program is the requirement that it must understand the HTTP request/response headers and that it usually will be dealing with HTML in some manner. Frequently, CGI applications are small, quickly built programs that perform some simple task. As the Web grows more sophisticated, however, CGI applications will become larger and more complex.
Q What is per-directory access?
A Each of the directories within your public-directory tree can be password protected. The access.conf file defines the overall structure of directory access, but you can add a similar file (usually called .htaccess) that creates special directory protection for the directory tree in which it is installed. You learn more about per-directory access in Tutorial 12.
Q How can I tell whether a variable exists?
A Perl provides a function called defined. The syntax for defined follows:
returns True if the variable has data stored in it; False is returned if neither a valid string nor numeric data is stored in the variable.
Q Couldn’t I store my name in one scalar variable?
A Sure. Using multiple scalar variables for your name was just a convenience for Exercise 1.2. You could substitute the following for lines 2-4 of Exercise 1.2:
$name = "Eric C. Herrmann";

Leave a Reply

Your email address will not be published. Required fields are marked *