PerlHoo, Part II | 5
PerlHoo, Part II
Handling the Query String
Now that we know how to build a URL that sends an add request to the script, we will modify the perlhoo.pl script to handle it.
Let's begin by looking at Line 28:
use CGI::Carp qw(fatalsToBrowser);
The CGI::Carp module prints detailed error messages to your Web server's error log. By passing in the fatalsToBrowser token, it will also print errors to the Web browser which helps greatly in the debugging process.
Next, please note that I've added $new_datafile at Line 34 which defines the filename that recommended sites will be added to until they're removed or added to the PerlHoo directory.
Moving on to Lines 44-52, notice that the main body of our
code now consists of an if->else control structure. Line 44
checks the value of
$query->param('keywords'). If the value is add, it
depending on whether the CGI request method was GET or POST. For our purposes, we will
use the GET method when we want to display the fill out form that users will use to recommend a new site.
When we submit data using the POST request method, the script assumes that a user has just completed
the form and is not sending the data to the script.
$query->param('keywords') doesn't equal add, the script jumps down
to Line 51 and executes
which prints the directory browse screens.
Produced by Jonathan
Created: April 20, 1999
Revised: April 21, 1999