Database Reference
In-Depth Information
{
print $row [ 0 ], $cgi -> br ();
}
$dbh -> disconnect ();
# Print page trailer
print $cgi -> end_html ();
To try the script, install it in your cgi-bin directory and request it from your browser as
follows:
http://localhost/cgi-bin/show_tables_oo.pl
The script includes the CGI.pm module with a use CGI statement, and then creates a
CGI object, $cgi , through which it invokes the various HTML-generation calls. head
er() generates the Content-Type: header and start_html() produces the initial page
tags up through the opening <body> tag. After generating the first part of the page,
show_tables_oo.pl retrieves and displays information from the server. Each table name
is followed by a <br /> tag, produced by invoking the br() method. end_html() pro‐
duces the closing </body> and </html> tags.
CGI.pm calls often take multiple parameters, many of which are optional. To enable
you to specify just those parameters you need, CGI.pm understands -name => value
notation in parameter lists. For example, in the start_html() call, the title parameter
sets the page title. The -name => value notation also permits parameters to be specified
in any order.
To use the CGI.pm function call interface rather than the object-oriented interface, write
scripts a little differently. The use line that references CGI.pm should import the method
names into your script's namespace so that you can invoke them directly as functions
without having to create a CGI object. For example, to import the most commonly used
methods, the script should include this statement:
use CGI qw(:standard) ;
The following script, show_tables_fc.pl , is the function call equivalent of the
show_tables_oo.pl script just shown. It uses the same CGI.pm calls, but invokes them
as standalone functions rather than through a $cgi object:
#!/usr/bin/perl
# show_tables_fc.pl: Display names of tables in cookbook database
# (use the CGI.pm function-call interface)
use strict ;
use warnings ;
use CGI qw(:standard) ; # import standard method names into script namespace
use Cookbook ;
# Print header, blank line, and initial part of page
Search WWH ::




Custom Search