Next: Why Are File Permissions
Up: Beginning CGI Programming in
Previous: A First Perl CGI
The Perl file that contains the CGI program should be placed in your
Web server's cgi-bin directory.
Then, the URL for this program will be something like http://localhost/cgi-bin/test.pl
(change localhost to correspond to your Web server's hostname).
Enter this URL into your Web browser and it should display a Web
page saying "This is a test."
Note
You may wonder how the Web server knows that a CGI program should be executed instead of being displayed. This is an excellent question. It can be best answered by referring to the documentation that came with your particular server.
When the Web server executes your CGI program, it automatically
opens the STDIN, STDOUT,
and STDERR file handles for
you.
- STDIN-The standard
input of your CGI program might contain information that was generated
by an HTML form. Otherwise, you shouldn't use STDIN. See "Inputs
to Your CGI Program" later in this chapter for more information.
- STDOUT-The standard
output of your CGI program is linked to the STDIN
of the Web browser. This means that when you print information
using the print() function,
you are essentially writing directly to the Web browser's window.
This link will be discussed further in the "HTTP Headers"
section later in this chapter.
- STDERR-The standard
output of your CGI program is linked to the Web server's log file.
This is very useful when you are debugging your program. Any output
from the die() or warn()
function will be placed into the server's log file. The STDERR
file handle is discussed further in the "Debugging CGI Programs"
section later in this chapter.
The Web server will also make some information available to your
CGI program through environment variables.
Next: Why Are File Permissions
Up: Beginning CGI Programming in
Previous: A First Perl CGI
dave@cs.cf.ac.uk