18

I have a program that has to read a configuration file from a PHP script, and a quick search has revealed there are dozens of ways to handle configuration files in Perl:

Brian provides an overview here.

Config::Simple will work for me, since the existing file is INI-like. I am interested to know what style people regularly use in their code though?

2
  • 3
    I have ambivalence about this question: It's basically a poll, and you're not likely to get enough answers for it to be meaningful. However, the question text itself reflects research effort and provides excellent resources in itself. The question is more useful than its answers :-P Commented Apr 14, 2009 at 13:20
  • I was trying to use Config:Abstract::Ini, but this question led me to some way better modules. Thank you!
    – Jason Down
    Commented Nov 26, 2009 at 14:33

4 Answers 4

11

I quite like using YAML configuration files. I find them to be very readable and easily manipulated. They fit naturally into Perl as well as the primary constructs are Arrays and Hashes.

3
  • 2
    Full-blown YAML is large and usually massive overkill for config files. YAML::Tiny is generally sufficient. It's small and easily bundled. Commented Apr 15, 2009 at 2:33
  • Furthermore, you could opt for YAML::Any. It will reach for any available YAML module, and choose according to this preference: YAML::XS > YAML::Syck > YAML > YAML::Tiny.
    – brunov
    Commented Apr 16, 2009 at 2:22
  • YAML is unpleasant to edit by hand (moving stuff around involves adjusting indentation levels, and punctuation that only shows up on the first lines of aggregates), and Perl has too many slightly-incompatible YAML parsers. Which is aided by the fact that YAML is really too big a language.
    – hobbs
    Commented Oct 3, 2010 at 3:16
6

One solution is to use Config::Any and let the user choose from many options. Personally, I prefer Config::General.

1
  • Second for Config::General. Config::Simple is ok, but Config::General is still really easy to use and provides far more features.
    – jiggy
    Commented Apr 15, 2009 at 19:16
3

One question you have to ask is what is the audience ? That is, are you happy having your target audience (config file users/modifiers) changing Perl code, or modifying a .INI-like file. That will certainly drive your decision to some degree.

2

If the audience is technical (used to formatted data structures), then I like using JSON for configuration. In your program it'll work like if you used YAML, but to me it's easier to read (and we use lots of JSON anyway).

If you use JSON::XS there's a "relaxed" option that'll allow comments and trailing commas and such in the files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.