Unfortunately, there are no cgi.pm books of excellent quality. All of them are mediocre.
It is advised that in order to broaden your understanding of
ScriptAlias /~loginname/cgi-bin/ /home/loginname/public_html/cgi-bin/
localhost.localdomain/~loginname/cgi-bin/filename.cgi
127.0.0.1/~loginname/cgi-bin/filename.cgi
CGI scripts are invoked multiple times to generate different pages. The first invocation occurs when your browser first visits the cgi script. During this first invocation, subroutine param() returns null. By testing for a null param(), the CGI script builds the 1st page. When you click the submit button, labelled 'Set' in this example, the CGI script will be invoked once again. In this 2nd invocation param() will actually return something. param() returns the values of form widgets from the last invocation. Calling param() by itself, gives you a list of names of widgets of the last invocation. If you call param() with a name of a widget, you get back the value of the widget. Be aware that param values only exist for one invocation. If you want param values to stay around, you'll need to add hidden widgets to the generated page to hold those values.
CGI.pm contains many functions that generate HTML for you. A bare basic script will look like this
print header; print start_html; ... print end_html;
In the CGI.pm every single HTML tag can be generated by the appropiate function call. These are only documented in their entirety by the Lincoln Stein book. Most other books just document the API for the form widgets.
In addition to using CGI.pm functions to generate HTML, you are allowed to print raw HTML,e.g.
print q # q {} is the same thing as single quoting { <table> <tr> <th>header</th> <td>data</th> </tr> </table> }
Hint: Syntax errors in your cgi script can be ferreted out if you do
perl -c filename.cgi
Hint2: use view->source from your browser to look at the generated source
-script => q # q{} is the same thing as single quoting { // Your JavaScript here }
Multi page cgi scripts typically have a format that looks like something like this
my $go = param ('go'); if (!param || $go eq 'start_over') { start_page(); } elsif ($go eq 'first') { first_page(); } elsif ($go eq 'cart') { shopping_cart(); } else { die "Unexpected page request\n"; }
<a href="restaurant.cgi?go=food_name">