in reply to Re: Require Centralized Variables
in thread Require Centralized Variables

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.