Programming Perl 101

Welcome to section two of this Perl Tutorial. In section one, you were shown how a Perl script can take information submitted via an HTML and display the results back to the person submitting the form by making use of variables. Variables are the core of the Perl language, so today we're going to learn a bit more about them.

1 - Test.html
Create another HTML page and name it "test.html." Put the following code onto the page:

<html>
<head>
<title>Test.html</title>
</head>
<body>
<form action="http://www.yourdomain.com/cgi-bin/test.cgi" method="post">
<input type="hidden" name="action" value="1">
<input type="submit" value="Page 1">
</form>
<hr>
<form action="test.cgi" method="post">
<input type="hidden" name="action" value="2">
<input type="submit" value="Page 2">
</form>
<hr>
<form action="test.cgi" method="post">
<input type="hidden" name="action" value="3">
<input type="submit" value="Page 3">
</form>
</body>
</html>

Don't forget to substitute the form action URL with the path to your test.cgi file.

Notice the forms…they have only a submit button, and a "hidden" form field. This form field is obviously invisible to the visitor, however it can still hold a variable. If we click on the first button (labeled "Page 1"), it will pass the data along to the test.cgi file. Which data, you ask? Why, the data that says that the "action" field has a value of "2" of course! Using these values, we can tell the script to determine which button was pressed, and display the corresponding text and/or HTML.

Obviously the next step is to create the test.cgi file…let's do that now.