Database Reference
In-Depth Information
print
$page
;
Creating a multiple-page navigation index
This example shows a Perl script,
esther2.pl
, that is capable of generating any of several
pages, all based on the verses in the topic of Esther stored in the
kjv
table. The initial
page displays a list of the chapters in the topic, along with the verses from chapter 1.
Each item in the chapter list is a hyperlink that reinvokes the script to display the list of
verses in one of the other chapters. Because the script is responsible for generating
multiple pages, it must be able to determine which page to display each time it runs. To
make that possible, the script examines its own URL for a
chapter
parameter that in‐
dicates the number of the chapter to display.
The URL to request the initial page looks like this:
http://localhost/cgi-bin/esther2.pl
The links to individual chapter pages have the following form, where
cnum
is a chapter
number:
http://localhost/cgi-bin/esther2.pl?chapter=
cnum
esther2.pl
uses the CGI.pm
param()
function to obtain the
chapter
parameter value,
defaulting to 1 if the chapter is missing or not integer-valued:
my
$cnum
=
param
(
"chapter"
);
# Missing or malformed chapter; default to chapter 1.
$cnum
=
1
if
!
defined
(
$cnum
)
||
$cnum
!~
/^\d+$/
;
Here is the entire
esther2.pl
script:
#!/usr/bin/perl
# esther2.pl: display the topic of Esther over multiple pages,
# one page per chapter, with navigation index
use
strict
;
use
warnings
;
use
CGI
qw(:standard escape escapeHTML)
;
use
Cookbook
;
# Construct navigation index as a list of links to the pages for each
# chapter in the the topic of Esther. Labels are of the form "Chapter
# n"; the chapter numbers are incorporated into the links as chapter=num
# parameters
# $dbh is the database handle, $cnum is the number of the chapter for
# which information is currently being displayed. The label in the
# chapter list corresponding to this number is displayed as static
# text; the others are displayed as hyperlinks to the other chapter
# pages.