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

Managing Configuration Differences & Perl

by eak (Monk)
on Sep 22, 2003 at 15:11 UTC ( #293145=perlquestion: print w/replies, xml ) Need Help??

eak has asked for the wisdom of the Perl Monks concerning the following question:

I frequently run in to the case where I have an application that is configured differently based on environment (dev, qa, prod, etc). Things like the database, email addresses, urls change. I can't really have one config file since it the values need to change. Any suggestions on how to manage this?

  • Comment on Managing Configuration Differences & Perl

Replies are listed 'Best First'.
Re: Managing Configuration Differences & Perl
by DrHyde (Prior) on Sep 22, 2003 at 15:20 UTC
    Try using two configuration files, one for global settings and one for local settings, where the local settings can override the global settings.
      Or just define a section in the whole configuration file for settings that are expected to be changed. You need to edit one file anyway - there is not much difference if you edit the whole main file or if you edit a separate file.

      I am wondering what answer expects the OP? There is not much field to maneuvre.

Re: Managing Configuration Differences & Perl
by sgifford (Prior) on Sep 22, 2003 at 16:00 UTC

    When I have a situation like this, I will just isolate all of the configuration-related code into a single perl module or require file, and then maintain those two files seperately from the rest of the code. When I sync versions between development and production machines, I just don't include that file. That means I have to update it by hand if new variables are added, but if you keep the number of configurable things small you don't have to modify it very often anyways.

Re: Managing Configuration Differences & Perl
by welchavw (Pilgrim) on Sep 22, 2003 at 16:12 UTC

    I have faced about the same problem. I use hashes that look like this...

    $inf = { test => { host1 => { app => { setting1 => 'foo', setting2 => 'bar', }, }, host2 => { app => { setting1 => 'baz', setting2 => 'buz', }, }, }, dev => { host3 => { app => { setting1 => 'a', setting2 => 'b', }, }, host4 => { app => { setting1 => 'c', setting2 => 'd', }, }, }, };

    My perl scripts typically end up rewriting configuration files based on environment/host, using the hash to drive the rewrites. I take this approach because I use a system like this to configure large numbers of COTS products along with proprietary software for a large number of environments and hosts.

Re: Managing Configuration Differences & Perl
by simonm (Vicar) on Sep 22, 2003 at 18:53 UTC
    Another suggestion -- create one global config file and several separate config files, one for each environment, all of which can be copied to all of the hosts.

    Then, on each machine, create an environment variable or a one-line text file named something like local.config that contains the name of the environment.

    When the script starts up, pull in the global config, then read the local.config and pull in whatever config file it names. Put default values in the global config file and let the local configs override them.

    That way, your various config files can all be in the same CVS archive or the same distribution tarball, and the only the changes is the name of the config file you want loaded.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://293145]
Approved by broquaint
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2022-01-28 22:26 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (74 votes). Check out past polls.