in reply to Require Centralized Variables

Instead of require-ing the variables from conf.pl why don't you use one of the many modules that let you store and retrieve variables, such as Storable, FreezeThaw, Data::Denter, Data::DumpXML, XML::Simple... or just use your own module, which would then let you export variable as well as functions.

In any case you should pay extra attention to where the data file is located (outside of the web tree is a good idea) and what its permissions are (probaly not writeable by the web server user).

Replies are listed 'Best First'.
Re: Re: Require Centralized Variables
by chromatic (Archbishop) on Nov 20, 2002 at 17:47 UTC

    Let me second this! As usual, mirod knows well what he is saying.

    I worked on a project earlier this year that had URIs and paths hardcoded throughout the programs. Whenever one program was moved from testing to production, the original coder had spent several minutes manually editing the paths, as the testing and production environments were different. (They should have been the same, but that is a story for another time.)

    One of the first things I did was to write a small module based on Data::Denter. It looked in the same location on the production and testing boxes for a configuration file. It loaded all of the configuration values into a hash and made them available. Then, I removed all of the paths and URIs and put them in the configuration file. Finally, I defined constants in all of the programs, and added code to load the configuration module and to populate the important constants.

    This turned out to be an even bigger win in one circumstance. I wanted to do some profiling of some detailed code, so I added debugging sections. Because I didn't want to slow things down in general, I used the if (0) {} trick -- and I could control whether or not the debugging code was stripped by the optimizer simply by changing one value in the configuration file.

Re^2: Require Centralized Variables
by adrianh (Chancellor) on Nov 20, 2002 at 20:10 UTC

    YAML would be another one I would add to mirod's list.

    You might also want to consider one of the Config:: modules as an alternative.


    (hmmm... just realised that this was my 100th post...)