I don't think you want to "use vars" for your regular variables.  Too
dangerous, and you set yourself up for memory leaks.  Declare them as
lexicals. Only use a global for something you want to cache ($dbh). 
Something like:


      #!/usr/bin/perl -w

      # some sample code
      use strict;
      use MyStuff;


      sub something {
             my $dbh = dbConnect;
             my $foo = "somevvar";
             my $sth = $dbh->prepare("some sql code");
             $sth->execute();
             my $bar = $sth->fetchrow();
             $sth->finish;
      }

      ----------------------------------
      package MyStuff;

      use strict;
      use DBI;
      use vars qw($dbh);

      # export dbConnect, etc

      sub dbConnect {
             $dbh ||= DBI->connect(args,to,dbi);
             return $dbh;
      }
      1;
      # end of MyStuff;
      ---------------------------


[EMAIL PROTECTED] (Wim Kerkhoff) wrote:
># some sample code
>use strict;
>use MyStuff;
>use vars qw ($dbh $foo $bar $sql $sth $rc);
>
>$dbh = dbConnect;
>
>sub something {
>        $foo = "somevvar";
>        $sth = $dbh->prepare("some sql code");
>        $sth->execute();
>        $bar = $sth->fetchrow();
>        $sth->finish;
>}
>
>----------------------------------
>
>package MyStuff;
>
>use strict;
>use DBI;
>
># export dbConnect, etc
>
>sub dbConnect {
>        my $dbh = DBI->connect(args,to,dbi);
>        return $dbh;
>}
>1;
># end of MyStuff;
>---------------------------


Reply via email to