At 11:06 AM 11/8/01 -0500, Jeff 'japhy' Pinyan wrote:
>On Nov 8, Tomasi, Chuck said:
>
> >I have a series of related programs that need global definitions ($DOMAIN,
> >$ADMIN, $DBNAME, etc). My code looks something like this:
>
>Global variables aren't declared with my(). It sounds like you want to
>use the Exporter module.
>
>Your base program remains the same:
>
> use DBI;
> use strict;
> require "defs.pl";
>
> print "Welcome to $DOMAIN, $ADMIN\n";
Global symbol $DOMAIN requires explicit package name...
>But defs.pl changes a bit:
>
> package Defaults;
> require Exporter;
> @ISA = 'Exporter';
> @EXPORT = qw( $DOMAIN $ADMIN );
>
> $DOMAIN = "...";
> $ADMIN = "...";
>
> Defaults->import;
>
> 1;
I don't think you want to call the import method from within the Defaults
package.
>That works. However, you might want to take the full-fledged module
>approach. Your main program will then do
>
> use Defaults;
>
>instead of
>
> require "defs.pl";
>
>And your defs.pl file should be renamed Defaults.pm. The contents will be
>almost exactly the same, except you should remove the call to
>Defaults->import.
Agreed, much simpler.
It's worth pointing out that strictness isn't being applied to Defaults.pm
just because it is on in the main program. It was a *long* time before I
realized this.
If you enable it so you can strict-check your modules, then you have to do
something about the variables you're exporting... IMHO the easiest way is
to insert
use vars qw(@ISA @EXPORT $DOMAIN $ADMIN);
sufficiently early.
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]