views:

831

answers:

4

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  A: 

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.

Brian Agnew
+5  A: 

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

cubabit
Second for Config::General. Config::Simple is ok, but Config::General is still really easy to use and provides far more features.
jiggy
+6  A: 

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.

Adam Pope
Full-blown YAML is large and usually massive overkill for config files. YAML::Tiny is generally sufficient. It's small and easily bundled.
Michael Carman
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
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
+1  A: 

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.

Ask Bjørn Hansen