in reply to Re: using modules
in thread using modules

Thank you all for your help. The reason why I'm putting a bit of code into the SUBS package is that I've got about 5 different CGI scripts which get information out of SUBS - it saves me repeating alot of code. My solution was as follows. In SUBS:
package SUBS; use Exporter; @ISA = qw(Exporter); @EXPORT = qw ($log $site $base $dbh); use vars qw ($log $site $base $dbh); sub connectdb() { #Open the Oracle database: my($dbline,@dbinfo); if (!defined(open(DBINFO, "$base/dbinfo"))) { die "Can't open dbinfo.\n"; } while(defined($dbline = <DBINFO>)) { chomp($dbline); push @dbinfo, $dbline; } close(DBINFO); $dbh = DBI->connect($dbinfo[0],$dbinfo[1], $dbinfo[2],$dbinfo[3], { RaiseError => 1, AutoCommit => 1} ); $dbh->trace(2,"$log"); }
While in db.cgi:
package SUBS; use SUBS; . . . &connect_db();
The main difference betwee this example and my original post was that I am now using use SUBS as opposed to require SUBS as before. I'm also using 'use var'. SUBS also now exports only those variables used by db.cgi in the @EXPORT array. Again, thanks for all your suggestions.
Stacy.

Replies are listed 'Best First'.
Re: Re: Re: using modules
by davorg (Chancellor) on Nov 09, 2001 at 20:35 UTC

    I'm still not convinced that the use SUBS statement in db.cgi is doing anything useful. Try removing it and seeing if anything breaks.

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you don't talk about Perl club."

      I tried removing the use SUBS statement, but I received the following:
      BEGIN not safe after errors--compilation aborted at db.cgi line 1035.
      Line 1035 is: chdir("$file_dir");
      However, I also received error messages like:
      Global symbol "$var" requires explicit package name at db.cgi
      The "$vars" are those I have declared in @EXPORT and use var in SUBS.
      Stacy.