Sams Teach Yourself Perl in 24 Hours (3rd Edition)
| < Day Day Up > |
| After all the fanfare, warnings, checklists, and runaround, you're ready to type in your first CGI program. It is shown in Listing 21.1. Type and save this program as hello . If, in the checklist, you are required to use a certain extension for CGI programs ”as noted in the "Extension to be used for CGI programs" item ”use that extension. Thus, if you're required to name your CGI programs with a .cgi extension, save this script as hello.cgi . If you're required to use .pl, save this script as hello.pl . You did fill out the checklist, didn't you? Listing 21.1. Your First CGI Program
1: #!/usr/bin/perl -w 2: use CGI qw(:standard); 3: use strict; 4: 5: print header; 6: print "<b>Hello, World!</b>";
Line 1 : This line is the standard #! line. You must substitute the path from the checklist item "Location of Perl on the web server" for this script to work. The -w , of course, enables warnings. Line 2 : The CGI module is included in the program. The qw(:standard) causes the standard set of functions from the CGI module to be imported into your program. Line 3 : use strict enforces good coding practices; this is no different for CGI programs. Line 5 : The header function is imported from the CGI module. It prints a standard header that the server (and the client) must see to process the output of the CGI program. Line 6 : After the header is printed, any output will appear normally to the browser. In this case, when the CGI is run, the browser will display the words Hello, World . That's it! Well, not quite. You still have to install this CGI program and test it. You've won only half the battle. Installing the CGI Program on the Server
How you install your CGI program depends heavily on what kind of server you have, whether you have local access to it, whether it's a server that you can only FTP files to, and so on. The following sections describe how to install for the different scenarios. Local Access to a File System on a Unix Web Server
Use these instructions if you're able to telnet, rlogin, or otherwise log in to the Unix web server:
FTP-Only Access to a Unix Web Server
Use these instructions if you have FTP-only access:
|