baxy77bax has asked for the wisdom of the Perl Monks concerning the following question:
is there a more delicate way to do this? i have a script that uses a subroutine from a module. example
and now there is a module that contains subroutine:"Test.pl" use strict; use DBI; use DB qw(:All); use SQL::Abstract; my $sql = SQL::Abstract->new(); my $dbh = DBI -> connect("dbi:SQLite:dbname=test.db", "", "",{RaiseErr +or=>1, AutoCommit=>1}); my $popsamp = [qw(Popl Samp)]; my $form2 = "ID varchar(40) not null"; createtb($form2,$popsamp,$dbh);
now the problem is that i have to pass $dbh variable to a module to work, but this seams very unprofessional(not that i am one). so i was wondering is there some other way to make variable available to the modules of my interest(specificaly a subroutines in the module)package DB; use strict; use base qw(Exporter); use vars qw(@EXPORT_OK); @EXPORT_OK = qw(createtb); sub createtb{ my ($form, $tabler, $dbh) = @_; my @table = @$tabler; foreach my $table (@table){ my $stm = "create table $table ($form)"; my $stm1 = $dbh -> prepare($stm); $stm1 ->execute; } }
thanx
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Database module question
by CountZero (Bishop) on Jun 14, 2008 at 15:42 UTC | |
|
Re: Database module question
by almut (Canon) on Jun 14, 2008 at 15:51 UTC | |
|
Re: Database module question
by blahblah (Friar) on Jun 14, 2008 at 19:07 UTC | |
by doom (Deacon) on Jun 14, 2008 at 21:37 UTC |