in reply to Config Files in Perl

Dear Fellow Monk,
Powerful, appropriate and favorable are all in the eye of the beholder IMHO. I've used many approaches to storing configuraiton information for an application with varying degress of ease, beauty and "power."

One factor I take into consideration when planning which approach I'm going to use is who is going to be editing the configuration data and how often do they have to do it?

Quite a few of my scripts are "self configuring" in that they make best guesses about how they are to be configured based on some knowlege of the platform and/or system they are running on. Other scripts run a configuration "wizard" the first time they run and write the configuration somewhere for persistance.

Other scripts I make the poor user edit a config file by hand. The CPAN module that I like to use for this sort of thing is AppConfig which allows for a very simple syntax for configurtion files making it easy for folks to edit. This is important to me in cases where the user community might not be that sophisticated.

Another approach I use quite often is to use XML files and use XML::Simple to deal with them. The issue I have here (and has been mentioned elsewhere) is the fact that XML is great for folks that understand how to use it properly but can cause your program to misbehave if the person editing the XML file makes mistakes and creates ill formed XML. A good example of that that I ran into recently is an application that I wrote where I took XML as the input to load entries in a database. The perosn who created the XML file to be used as input put characters into the input that caused problems for the parser such as ampersands and single quotes. Bad ju-ju.

I've also been known to persist configuration information in a databsse table if my script or application is database driven. This usually means that I either use a wizard for the initial configuration or in one case I wrote an application that had a command line switch that meant "use the values on the command line as defaults and persist them" which is a valid approach no matter what method you use to persist the values.

There's lots of ways of doing what you're after, but you have to more or less decide in each case what best suits the situation and that you're comfortable using.


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

Replies are listed 'Best First'.
Re^2: Config Files in Perl
by narashima (Beadle) on Nov 24, 2006 at 17:29 UTC
    Thanks all for your insigtful commnets.
    I believe that using a config file should really be dependent on the user.
    My users are programmers with good knowledge of Perl and so I am going to use a perl based config file and then do a 'do' to get all the config into the script.

    Thanks again

    Perl Rulez!