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

In reply to Re: Config Files in Perl by blue_cowdawg
in thread Config Files in Perl by narashima

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.