On 3/14/2004 9:58 AM, B. Fongo wrote:

I have several modules which needs global variables from a text file
(global.txt).
Within each module, I use require "global.txt" to get my variables.
----------------------------------------------------------------
global.txt
----------------------------------------------------------------
$shop = "Shop name";
$sendmail = "/usr/./sendmail";
$email = "[EMAIL PROTECTED]";
and so on.
---------------------------------------------------------------
But strangely enough, all my modules get the first variable in text file
and warm that the rest are uninitialized.
I'm a bit confused on what that might mean.

The usual idiom is to create a Config package for your module:


package MyModule::Config;

use strict;

use vars qw($shop $sendmail $email);

$shop = "Shop name";
$sendmail = "/usr/./sendmail";
$email = "[EMAIL PROTECTED]";

# Constants

use constant $var_that_should_not_change_value => 1;
...

__END__

Then in your module:

use MyModule::Config;

print $MyModule::Config::shop;
...


You can use Exporter (see perldoc Exporter) if you want to access the variables without their fully qualified names.


Regards,
Randy.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to