How do you manage configuration files in Perl?

后端 未结 4 1556
失恋的感觉
失恋的感觉 2020-12-06 01:00

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:

相关标签:
4条回答
  • 2020-12-06 01:23

    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.

    0 讨论(0)
  • 2020-12-06 01:32

    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.

    0 讨论(0)
  • 2020-12-06 01:33

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

    0 讨论(0)
  • 2020-12-06 01:42

    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.

    0 讨论(0)
提交回复
热议问题