hi,

my question is , can i somehow pass a variable to a module at load time. example:

i now i can do this :

use foo qw(copy);

to call only the copy subroutine but if i have example like this :

First script:

use strict; use warnings; use lib "."; use Max; my $rrr = Max->new(); my $pform = "GeneID varchar(30) not null PRIMARY KEY"; my $tname = "PT"; $rrr->createtable(form => $pform, table => $tname);
second script:
use strict; use warnings; use lib "."; use Max; my $rrr = Max->new(); my $pform = "GeneID varchar(30) not null PRIMARY KEY"; my $tname = "PT"; $rrr->createtable(form => $pform, table => $tname);
module.pm
package Max; use strict; use DBI; my $robi; <------------ DEFINE THIS VARIABLE AT LOAD TIME my $dbh = DBI->connect("dbi:SQLite:dbname=$robi", "", "",{RaiseError=> +1, AutoCommit=>1}); + print "$robi"; ################################################## sub new { ################################################## my ($class) = @_; my $hash = {}; bless($hash,$class); } ################################################## sub createtable{ ################################################## my ($self, %arg)=@_; my $form = $self->{form}=$arg{form}; my $tabler = $self->{table}=$arg{table}; $self->drop(argument => $tabler); my $stm = "create table $tabler ($form)"; $self->do_it_db(argument => $stm); } ################################################## sub do_it_db { ################################################## my ($self, %arg) =@_; my $stm = $self->{argument}=$arg{argument}; my $st = $dbh->prepare($stm); $st ->execute(); } ################################################## sub drop { ################################################## my ($self,%arg) = @_; my $arg = $self->{argument}=$arg{argument}; my $statement = "drop table if exists $arg"; $self-> do_it_db(argument => $statement) } 1;
the point here is that i want to create at load time two different databases. first one when i start the first script and the second one when i start the second script and then to do the same stuff in side of them. the object my $dbh is specific for Max.pm so the form in which it is called should be preserved

please don't mind the amount of code i try to create a useful example !


In reply to pass variable at load time by baxy77bax

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.