How do you manage configuration files in Perl?
Asked Answered
T

4

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?

Tenancy answered 14/4, 2009 at 10:7 Comment(2)
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 :-PHyperboloid
I was trying to use Config:Abstract::Ini, but this question led me to some way better modules. Thank you!Billi
P
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.

Parapodium answered 14/4, 2009 at 18:0 Comment(3)
Full-blown YAML is large and usually massive overkill for config files. YAML::Tiny is generally sufficient. It's small and easily bundled.El
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.Vidda
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.Maggio
P
6

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

Philipines answered 14/4, 2009 at 11:39 Comment(1)
Second for Config::General. Config::Simple is ok, but Config::General is still really easy to use and provides far more features.Quartzite
H
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.

Hurtado answered 14/4, 2009 at 10:9 Comment(0)
D
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.

Dantedanton answered 15/4, 2009 at 5:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.