制作简单 Perl 配置文件的最佳方法是什么?

发布于 2024-10-07 04:47:27 字数 527 浏览 0 评论 0原文

我正在尝试为我的 Perl 脚本制作一个简单的配置文件,我最初打算使用 Config ::INIPlus 但我认为它不会起作用。配置文件不需要有什么特别的。我只需要能够读取和写入它。我想使用一个模块来完成此任务。

更新:

我不认为 Config::INIPlus 对我有用的原因可能听起来很愚蠢,但我想让配置文件维护特定的值顺序。我一直遇到的问题是 Config::INIPlus 模块坚持删除整个文件,然后按字母顺序重新插入所有值,无论它们属于哪个主题,所以它弄乱了我想保留配置的顺序文件已订购。它还删除了我留给占位符的空变量。

我使用注册表作为配置存储对我的想法进行了测试,效果非常棒!问题是,尽管我试图使我的脚本尽可能独立于平台,主要是 Windows 和 Linux,而不是 Mac,因为我没有 Mac。

也许我只需要重新思考我对配置文件的看法,也许我要求一些在我掌握更多 Perl 细节之前无法完成的事情。

I am trying to make a simple config file for my Perl script, I originally was going to use Config::INIPlus but I don't think it is going to work. The config file does not need to be anything special. I just need to be able to read and write to it. I would like to use a module to accomplish this.

Update:

The reason I don't think Config::INIPlus will work for me might sound stupid, but I want to have the config file maintain a specific order of values. The problem I keep running into is the Config::INIPlus module insists on erasing the entire file and then reinserting all of the values in alphabetical order regardless of there subject they pertain to so it messes up the order which I would like to keep the config file ordered. Also it erases my empty variables that I had left for place holders.

I had made a test of my idea using registry as the config storage and it was great! The problem is though I am trying to make my script a platform independent as possible mainly Windows and Linux not so much Mac as I don't own one.

Maybe I just need to rethink my view on the config file maybe I am ask for something that cannot be done until I grasp more the finer points of perl.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

‖放下 2024-10-14 04:47:27

如果您正在寻找简单的东西,我会尝试 Config::TinyConfig-INI

我不喜欢 Config::Simple 的是它试图支持太多不同的配置格式。

YAML、JSON 和 XML 都不是我所说的“简单”配置文件,尽管它们适合您有更复杂的需求。如果可能的话,我会避免使用 XML;在 $WORK 我编写了一个 YAML 到 XML 配置文件转换器,这样我就可以用 YAML 编写我的配置,而不是手动编辑 XML 配置文件。

更新问题的更新:当然可以编写一个保留现有行顺序的配置模块,但我不知道有任何现有模块可以做到这一点。您可能必须自己编写,或者雇用某人来编写。

If you're looking for something simple, I'd try Config::Tiny or Config-INI.

What I don't like about Config::Simple is that it tries to support too many different config formats.

Neither YAML nor JSON nor XML is what I would call a "simple" config file, although they are suitable if you have more complex requirements. I would avoid XML if at all possible; at $WORK I wrote a YAML-to-XML config-file-translator so I could write my config in YAML instead of hand-editing XML config files.

Update for updated question: It's certainly possible to write a Config module that preserves the order of existing lines, but I'm not aware of any existing one that does that. You'd probably have to write your own, or hire someone to write it.

绻影浮沉 2024-10-14 04:47:27

YAML? JSON? XML?有很多可能性,每种都有一个 Perl 模块。还有普通的旧文本,但如果您必须使用模块,只需选择一个标准。

YAML? JSON? XML? there are many possibilities, each with a Perl module. There's also plain old text, but if you must use a module, just pick a standard.

隔岸观火 2024-10-14 04:47:27

Config::Simple 怎么样?还有一些相关的模块。

What about Config::Simple? There are some related modules too.

拥抱我好吗 2024-10-14 04:47:27

尽管我确实喜欢 Config::Simple 并且它对我来说非常有用一些项目,我最喜欢的是 AppConfig

Even though I do like Config::Simple and it was very useful to me in a few projects, my favorite is AppConfig.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文