Testing the Script

Before actually installing the script on your Web server, it's helpful to be able to test it to make sure you haven't made any obvious errors. Using CGI.pm, you can run a CGI script from the command line to test it, like this:

% name.pl
(offline mode: enter name=value pairs on standard input)

After that line, you can enter sample form input as a name=value pair. For example, for the Hello form the name is “name” and the value would be a sample name (like “Fred”), so you'd type:

name=Fred

You don't have to include quotes unless the input has spaces in it. After you've entered your name and value pairs, hit Ctrl-D (Ctrl-Z on Windows) to end the standard input. The script will then run as if it had received that input from the form, and output the result to the screen.

Alternatively, you can also enter the names and values as arguments to the script's command line:

% name.pl name=Fred
					

The script will then use those name=value pairs as the input, and not prompt you for more.

When you've verified your CGI script works as you expect, the final step is to install it on your Web server. Installation might involve putting the script in a special directory called cgi-bin, renaming it with a .cgi extension, or indicating by some other method to the Web server that your script is a CGI script. (Again, this varies from server to server, so see the docs that came with your server to figure it out). You may also need to make sure the script is executable or to give it special user permissions. And, finally, you'll need to modify the original HTML file to point to the actual location of the script.

With all that out of the way, you should then be able to bring up the HTML for the form, fill in a name, click the Submit button, and have the CGI script give you a response. Figure 16.3 shows the response as a Web page.

Figure 16.3. Hello, the response.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.180.70