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:
我有一个程序必须从PHP脚本中读取配置文件,快速搜索显示有很多方法可以处理Perl中的配置文件:
- Config data in a separate file
- 将数据配置在单独的文件中
- AppConfig
- AppConfig中
- Config::General
- 配置::一般
- Config::IniFiles
- 配置:: IniFiles
- Config::Scoped
- 配置::作用域
- Config::Simple
- 配置::简单
- ConfigReader::Simple
- ConfigReader ::简单
- And many others
- 还有很多其他人
Brian provides an overview here.
Brian在这里提供了一个概述。
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?
Config :: Simple对我有用,因为现有的文件类似于INI。我有兴趣知道人们经常在他们的代码中使用什么样的风格?
4 个解决方案
#1
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.
我非常喜欢使用YAML配置文件。我发现它们非常易读且易于操作。它们自然适合Perl,主要构造是数组和哈希。
#2
6
One solution is to use Config::Any and let the user choose from many options. Personally, I prefer Config::General.
一种解决方案是使用Config :: Any并让用户从许多选项中进行选择。就个人而言,我更喜欢Config :: General。
#3
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.
你要问的一个问题是观众是什么?也就是说,您是否乐意让目标受众(配置文件用户/修饰符)更改Perl代码或修改类似.INI的文件。这肯定会在某种程度上推动你的决定。
#4
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).
如果受众是技术人员(用于格式化数据结构),那么我喜欢使用JSON进行配置。在你的程序中它会像你使用YAML一样工作,但对我来说它更容易阅读(我们还是使用了大量的JSON)。
If you use JSON::XS there's a "relaxed" option that'll allow comments and trailing commas and such in the files.
如果您使用JSON :: XS,则会有一个“宽松”选项,它允许在文件中添加注释和尾随逗号等。
#1
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.
我非常喜欢使用YAML配置文件。我发现它们非常易读且易于操作。它们自然适合Perl,主要构造是数组和哈希。
#2
6
One solution is to use Config::Any and let the user choose from many options. Personally, I prefer Config::General.
一种解决方案是使用Config :: Any并让用户从许多选项中进行选择。就个人而言,我更喜欢Config :: General。
#3
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.
你要问的一个问题是观众是什么?也就是说,您是否乐意让目标受众(配置文件用户/修饰符)更改Perl代码或修改类似.INI的文件。这肯定会在某种程度上推动你的决定。
#4
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).
如果受众是技术人员(用于格式化数据结构),那么我喜欢使用JSON进行配置。在你的程序中它会像你使用YAML一样工作,但对我来说它更容易阅读(我们还是使用了大量的JSON)。
If you use JSON::XS there's a "relaxed" option that'll allow comments and trailing commas and such in the files.
如果您使用JSON :: XS,则会有一个“宽松”选项,它允许在文件中添加注释和尾随逗号等。