Programming Perl 101

As you've probably noticed, first, city and food have a dollar sign in front of them. Perl requires that all variables or containers used in a script begin with the $ sign.

That first line, as I said before, is telling the browser that whatever form field had the name of "first" in the HTML file, now has the name of "$first".

What this allows us to do is use "$first" variable elsewhere in the Perl. What will happen is that $first will be replaced by whatever the user entered into the "first" field on the feedback form!

Starting to see where this is going?

Now, copy and paste this into the display.cgi file:

print "Content-type: text/html

";
print "Thank you, here is the information you entered:";
print "
  • $first
  • $city
  • $food
";

That first line tells the script that you'll be using HTML in one or more of the "print" statements. Now that the information from the form has been assigned new variables beginning with the $ sign, all we have to do is type those variable names out and the script will display what the user entered.

The print statement that you see above simply tells Perl to spit out the HTML code out to the browser after parsing it. Here's what Perl "thinks" when reading the above three lines:

- Line One: Hmm... we'll be working with HTML statements in one or more of the following print statements.

- Line Two: Ok, this one is simple. I'll just spit out the code between the quotation marks back out to the browser.

- Line Three: This line contains three variables named $first, $city and $food that I need to find and replace before sending out this line of code to the browser. I'll take the value of $first from the form field named "first" in the form that was just submitted to me, then I'll do the same for $city and $food. Now that I know what $first, $city and $food stand for, I can send this line of code to the browser with the replacements made.