Programming Perl 101

4 - Display.cgi
Now that we've got the form up (call the file whatever you like, just make sure that it has a .html or .htm extension) we'll move onto creating the Perl script to work with the data. The way this entire thing will work is:

Let's create display.cgi!

First, the shebang line:

#!/usr/local/bin/perl

Next, insert this:

require "subparseform.lib";
&Parse_Form;
 

Subparseform.lib is a widely used file that will aid us in the creation of this script. Do a search for it on the web and you should be able to find it. If your search fails, contact me and I'll give you some help.

Now, remember: we want this script to take the information from the form and display it to the user in such a way as to say "This is the information you entered." To do this we need to tell the script to "grab" the form information. But how? We simply have to match up those tags!

Enter this next:

$first = $formdata{'first};
$city = $formdata{'city'};
$food = $formdata{'food'};

Look familiar?

Take notice of a few things: first, the ";" sign is at the end of every line, as it should be. Second, the tag names: They match exactly with the tags on the form information. Take note of the equals sign ("="). That tells the script to assign the data entered into the form to a variable or container which we can use inside the Perl script. The first line is saying "make $first equal the information entered in the form field with the name 'first'".