use strict; use warnings; use diagnostics; use HTTP::Module; use Some::Module; my ($dbuser, # database username $dbpass, # password for db $dbhost, # host for the database $dbport, # db connection port $dbname, # name of the database used $dbh, # DBI handle $foo, # for foo $bar, # for bar $baz, # for baz %quux, # quux hash ); $dbuser = 'nobody'; $dbpass = 'NobodyPassword'; $dbport = '3306'; $dbhost = 'localhost'; $dbh = DBI->connect('DBI:mysql:$dbname:$dbhost:$dbport', $dbuser, $dbpass, {RaiseError => 1}); &init(); # initialize basic environment &print_header(); # CGI.pm basic header/content-type &top_of_page(); # print top menubars, logos, etc. &middle_of_page(); # main content, DBI results, etc. &bottom_of_page(); # bottom cleanup HTML, copyright, etc. &end_content(); # finish HTML, close handles if (!$vars{action} || $vars{action} eq "home") { # if the user hits the main page, or clicks 'home' # from the menubar, show the basic HTML content, no # sections &left_content(); &right_content(); } sub init { # ... } sub print_header { my $query = new CGI; %vars = $query->Vars(); # ... } sub top_of_page { # ... } sub middle_of_page { # ... $dbh = DBI->connect(..); # prepare, execute and print query results # wrapped in HTML elements } sub left_content { # Only shown when the user is on the main page # (no $vars{action} parsed) or they have # selected 'home' from the HTML menu displayed. # ... } sub right_content { # ..compliment to the 'left_content' sub above # ... } sub bottom_of_page { # ... } sub end_content { # ... } #### sub init { use strict; use warnings; use diagnostics; use HTTP::Module; use Some::Module; } sub print_header { my $query = new CGI; %vars = $query->Vars(); # ... } sub top_of_page { # ... } sub middle_of_page { # ... my ($dbuser, # database username $dbpass, # password for db $dbhost, # host for the database $dbport, # db connection port $dbname, # name of the database used $dbh, # DBI handle ); $dbuser = 'nobody'; $dbpass = 'NobodyPassword'; $dbport = '3306'; $dbhost = 'localhost'; $dbh = DBI->connect('DBI:mysql:$dbname:$dbhost:$dbport', $dbuser, $dbpass, {RaiseError => 1}); } sub left_content { if (!$vars{action} || $vars{action} eq "home") { # print the generic left content here } # ... } sub right_content { if (!$vars{action} || $vars{action} eq "home") { # print the generic right content here } # ... } sub bottom_of_page { # ... } sub end_content { # ... }