Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
index.pl -------- #!/usr/bin/perl use strict; use vars qw($dbh %sth %config %globals); use CGI qw(:standard); use DBI; use My::Database; use My::Globals; use My::Package_A; connectDB(); my $content = "dbh = $dbh<br>"; outputHTML($content); exit; ----------------------- package My::Database; use strict; use base 'Exporter'; our $VERSION = '1.0'; our @ISA = ('Exporter'); our @EXPORT = qw(connectDB $dbh); use vars qw($dbh); sub connectDB { $dbh = DBI->connect("DBI:mysql:database='database_name';host='host +_name'", 'user_name', 'password', {RaiseError => 1, AutoCommit => 0}) +; } 1; ---------------------------------- package My::Globals; use strict; use base 'Exporter'; our $VERSION = '1.0'; our @ISA = ('Exporter'); our @EXPORT = qw(%globals); use vars qw(%globals); sub load_globals { %gloabls = (); $globals{'image_directory'} = '/path/to/image/directory'; } 1; --------------------------- package My::Package_A; use strict; use base 'Exporter'; use CGI qw(:standard); our $VERSION = '1.0'; our @ISA = ('Exporter'); our @EXPORT = qw(outputHTML); sub outputHTML { my ($data) = $dbh->selectrow_array(qq|SELECT data FROM table WHERE + 1|); my $html = shift; print header; print <<HTML; <head> </head> <body> <p>$html</p> <p><img src="$globals{'image_directory'}/image.jpg"></p> <p>$data</p> </body> </html> HTML } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sharing Variables and Routines between modules
by Marshall (Canon) on Nov 01, 2010 at 21:03 UTC | |
|
Re: Sharing Variables and Routines between modules
by happy.barney (Friar) on Nov 01, 2010 at 17:32 UTC | |
by Anonymous Monk on Nov 01, 2010 at 18:45 UTC | |
by happy.barney (Friar) on Nov 01, 2010 at 19:14 UTC | |
|
Re: Sharing Variables and Routines between modules
by scorpio17 (Canon) on Nov 02, 2010 at 13:20 UTC | |
by Anonymous Monk on Nov 03, 2010 at 10:53 UTC |