Using Parameterized Links
Now let’s
take
a look at those subroutines that are performed for the various
unless-elsif
blocks. The first one is the
&show_links
routine, which just sticks some HTML
in the $content
variable to display three links.
When the user clicks on any of those links, the links will re-invoke
the script to perform various actions:
sub show_links { $content = <<EndOfText; <H1>Select an action:</H1> <P><STRONG><A HREF="make_page.cgi?action=show_student_form">Make a student page</A><BR> <A HREF="make_page.cgi?action=show_leader_form">Make a leader page</A><BR> <A HREF="make_page.cgi?action=regenerate_site_links">Regenerate site links</A> </STRONG></P> EndOfText
Note how using CGI.pm
makes it easy to mix and match
POST
- and GET
-method
invocations of the script. In this case, we’re using the
GET
method, creating links with parameters
embedded in the URL. A
question mark (?
)
separates the actual scriptname from the query string, which consists
of name=value
pairs. Using
CGI.pm
to retrieve the invocation parameters, our
script can ignore the different mechanics involved in retrieving and
decoding these parameters, as compared to how it would retrieve and
decode parameters passed as part of a POST
-method
HTML form submission.
Tip
If you have multiple parameters to embed in a
GET
-method CGI script invocation, you
use an ampersand to separate each pair. If you need to include
characters that aren’t legal in a URL, you need to
URL-escape
them, replacing a space character ...
Get Perl for Web Site Management now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.