If you've defined your $DBH in common.pm, then to access it you have to include the namespace:
my $sth = $common::DBH->prepare("......");

And in your common.pm, use our instead of my to share the variable:
our $DBH = DBI->connect ( "DBI:mysql:database=sample; host=127.0.0.1","root", "password");


Jaime Teng wrote:
Hi,

In my current web project, I group common functions and global variables into a separate file;

my problem is, I could not seem to be able to access these variables



##############
common.pm
use strict;
use DBI;
my $HTTP;
my $DBH = DBI->connect ( "DBI:mysql:database=sample; host=127.0.0.1",
"root", "password");

sub function1 {
}
sub function2 {
}
sub function3 {
}
1

##############
main.pl
use common.pm
my $sth = $DBH->prepare("......");

I am getting:
Global symbol "$DBH" requires explicit package name at main.pl line 2.

I dont know how to make it work. I appreciate if you could lend me a hand.

This is a web cgi application to be used with modperl, will there
be any "scope" problem? Last time I did a modperl based project was more than 5 years ago and have forgotten all about it.

Thanks.
Jaime

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to