in reply to Application-wide configuration

Someone once asked me to help them learn the right way to fish. My answer to that person was you learn the way to fish that is right for you and the kind of fish you want to catch.

Same is very true in my humble opinion about your question. There are many right ways to do it.

First off I'm a big fan of using XML::Simple to parse in an XML file that I have stored on the system that the script is going to run on someplace predictable. Just so happens that with XML::Simple this can be a no brainer because the default behavior for the method XMLin, one of the methods the module defines, is to look for a file with the same base name as the script you are running, in the directory the script is running from with the extension ".xml". The module also provides for pathing behavior as well.

The module you show in your example is a good start. One trick I've used is to use $0, strip off any extensions to it and use that as a key into my XML file for where the application data lives.


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Replies are listed 'Best First'.
Re^2: Application-wide configuration
by akho (Hermit) on Jul 27, 2007 at 19:04 UTC
    Config::Auto has similar magic, actually. I needed a different thing: I need to use a configuration file not only in the script itself, but also in several modules (such as database-related stuff). So I need to keep the configuration data (or at least a path to the config file) in some public place.