Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Include Constants from other files

by gregor-e (Beadle)
on Dec 01, 2002 at 04:11 UTC ( [id://216721]=note: print w/replies, xml ) Need Help??


in reply to Re: Include Constants from other files
in thread Include Constants from other files

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.... }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://216721]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-25 15:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found