Hamish Whittal wrote:
> Hi Everyone,
> 
> I am needing to use some variables throughout all the modules that I
> have created. I was wondering, bar setting them at the top of each
> module, what the best means of doing this is. Perhaps setting an
> environment variable, but what other ideas. The ultimate goal is to be
> able to change the value in the 'top-level' module and that should
> have an impact throughout all subsequent modules.

Create a module like this:

  Common.pm
  ---------
  package Common;

  use strict;
  use base 'Exporter';

  our @EXPORT = qw/$foo @bar %baz/;

  1;

Now, in each of your modules, add "use Common;"

The variables $foo, $bar, $baz will now be shared globals across all the
modules that "use Common". Changes to the value of one of these in any
module will be visible across all the modules, since they are all aliasing
the same set of variables.

(If you already have a common module used by all the other modules, just add
the "use base" and "our @EXPORT" lines to that module.)

perldoc Exporter (be sure to read this to learn about other options, and why
the practice of using @EXPORT is generally discouraged).

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

Reply via email to