> -----Original Message-----
> From: Walter Grace [mailto:[EMAIL PROTECTED]]
> Sent: Monday, October 29, 2001 3:21 PM
> To: [EMAIL PROTECTED]
> Subject: Exported variables
> 
> 
> 
> I have a variable in a module that I export (e.g. @EXPORT = 
> qw( $variable ); )
> 
> Do I have to de-reference (terminology?) it in any other 
> modules or scripts 

"fully qualify" not "de-reference"

> that include the given module (ie. $module::variable) or is 
> there a way to 
> import the variable so that I can refer to it directly?

That's the whole idea behind @EXPORT.

There are three ingredients to exporting symbols:

1. Your module needs to inherit from Exporter. This is done by adding
   "Exporter" to @ISA:

   require Exporter;
   our @ISA = qw(Exporter);

2. You need to include the symbols to be exported in @EXPORT or
   @EXPORT_OK.

   @EXPORT_OK = qw($foo $bar $baz);

3. Users of your module need to bring it in with "use":

   use MyModule;

"use" does two things: 1) require() your module, and 2) call your module's
import() method. Since your module inherits from Exporter and normally does
not override the import() method, Exporter's import() method get's called.
It's default behavior is to export all the symbols defined in @EXPORT_OK
to the package namespace which did the "use".

If you do these 3 things, you can refer to $foo, $bar, and $baz without
qualifying with a package name, since an alias for those symbols was
created in your current package.

For lots more info, see

   perldoc -f use
   perldoc Exporter
   perldoc perlmod

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to