
rovf
Veteran
Mar 15, 2012, 3:58 AM
Post #4 of 5
(620 views)
|
|
Re: [naven8] Using lexical variables from other files
[In reply to]
|
Can't Post
|
|
If I understand you right, the syntax of the config file should be Perl code. You could put the config file into its own package, and declare all the configuration variables (or constants) package global, i.e.
# configuration variable (config file should be evaluated with 'do') our $param=4711; or
# configuration constant (config file should be evaluated with 'require') use constant param => 4711; Assuming that the config file declarations end up in package MyProject::Config, you can access them as
$MyProject::Config::param or respectively. Of course there are other possibilities. Let's say your config file looks like this:
use strict; use warnings FATAL => 'all'; %MyProject::Config = ( param => 4711, # other configuration parameters go here ); you would access the configuration as $MyProject::Config{param}. Then, of course, you also have the possibility to choose a different syntax for your config file (for example, INI-File, XML-File). This depends a lot on the people who are actually writing the config file, and there is no general "best" solution.
|