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

I have a script that gets user options from the command line (using Getopt::Long) but the number of options is getting out of hand. I'm thinking of moving to a config file (or at least having the ability to use a config file instead of, or in addition to the command line options) but there are so many modules that deal with config files that I'm not sure which to use. This is my first Perl script of more than a handful of lines and I'm not at all what you'd call a Perl expert (in fact I probably don't know all the basics yet) so what I'm looking for is an EASY way to get options from a plain text configuration file (NOT XML), and write back one value that may be changed inside the script (which I guess means rewriting the entire config file with the changed value). In looking through the CPAN modules it seems there are many available, but I'm wonder which would be the easiest to use. One other thing, it should not be limited to a specific platform (right now the script runs on Windows, Mac OS X, and even some versions of Linux).

Again the major criteria for me at this point is that it be easy to use, preferably with a good explanation of how to use it. What module do you think would come closest to meeting that criteria? Any suggestions would be appreciated.

Replies are listed 'Best First'.
Re: What is easiest config file parser?
by poolpi (Hermit) on Mar 21, 2008 at 07:04 UTC

    See Config::Simple

    hth,

    PooLpi


    'Ebry haffa hoe hab im tik a bush'. Jamaican proverb
      Thank you for all the suggestions, I did wind up using Config::Simple, the only thing I'm not understanding is why it won't accept a relative path to the file. I am opening like this:
      if ($cfgpath) { use Config::Simple ('-lc'); my $cfg = new Config::Simple($cfgpath) or die "Could not find configuration file $cfgpath\n"; .....
      The problem is that if $cfgpath contains anything other than a full path and filename it doesn't work. If I just specify the config filename alone it doesn't find it, even if it's in the same directory as the script (which I can sort of understand, it's probably looking at some other directory) BUT it also won't work if I specify something like ~/temp/myconfig.cfg, even though the file exists. If I specify the full path then it works. Not a huge deal, I guess, but I wish I understood why that won't work.
        If you run the program in the directory it lives, then the program should be able to find the configuration file by relative path. Otherwise, there is no surprise that configuration file cannot be found; you may want to look in FindBin.
Re: What is easiest config file parser?
by skirnir (Monk) on Mar 21, 2008 at 08:11 UTC
    Maybe you should look into YAML. I find its format very human-readable and it also supports nested structures.
Re: What is easiest config file parser?
by dwm042 (Priest) on Mar 21, 2008 at 13:20 UTC
Re: What is easiest config file parser?
by jj808 (Hermit) on Mar 21, 2008 at 14:40 UTC
Re: What is easiest config file parser?
by apl (Monsignor) on Mar 21, 2008 at 13:41 UTC
Re: What is easiest config file parser?
by pascaldee (Acolyte) on Mar 22, 2008 at 06:08 UTC
    May I also suggest App::Options? I currently use this module most often, as it takes care of config from env vars, config files (at several possible locations), command-line options, as well as generate usage (--help) info.