in reply to Include Constants from other files

This is because your constants only exist in the namespace of your "header" file. What use constant camel => "flea-ridden" actually does is create a subroutine in the caller's namespace that returns the constant (and is normally inlined by the compiler).

Because said subroutine only exists in the namespace of your header file, your main program cannot access it. There are however a number of ways for your program to access this constant. Assuming header.pm contains your constants, and program.pl is your script

CU
Robartes-

Replies are listed 'Best First'.
Re: Include Constants from other files
by gregor-e (Beadle) on Dec 01, 2002 at 04:11 UTC
    If all you need is to #include a big hash of values from an external file, you can do something like:
    package MyConfig; sub new { my $proto = shift; my $class = ref($proto) || $proto; my $config = { "Servers to poll" => { # host login password "theophyline" => { "admin" => "secret" }, "caffeine" => { "admin" => "buzzword" }, "theobromine" => { "admin" => "mystery" }, }, "times to poll" => { "3:00 AM", "4:21 PM", }, }; bless($config, $class); return $config; } "the end";
    Then, in your main code, all you have to do is:
    use MyConfig; my $externalConfig = MyConfig->new(); foreach my $server (keys %{$externalConfig->{'Servers to poll'}}) { my ($login, $password) = each %{$externalConfig->{'Servers to poll'}->{$server}}; # etc.... }