如何在 Perl 中处理配置文件?
我正在重构一个旧脚本,该脚本在不同站点上执行一些操作。它需要使用一个配置文件,该文件现在是一个手动解析的文本文件,具有以下格式:
label:domain:username:password:path
当然,行数可能是无限的。
我知道有一些处理配置文件的模块。哪一个最适合这种情况?
I'm refactoring an old script that does some operations on different sites. It needs to use a configuration file which is now a manually parsed text file with this format:
label:domain:username:password:path
Of course the number of lines is potentially unlimited.
I know there are a few modules which deal with config files. Which one is the best for this situation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想更改格式,请查看此处的建议:
如何在 Perl 中管理配置文件?
如果您希望解析现有格式,该格式看起来更像是逗号分隔的文件比“配置”文件,所以我会说使用 Text::CSV (它允许您在构造函数中选择分隔符,因此您可以使用冒号分隔而不是逗号分隔),或者对于非常大的文件文本::CSV_XS。
If you are looking to change the format, please look at the recommendations here:
How do you manage configuration files in Perl?
If you're looking to parse the existing format, that format looks to be more of a comma-separated file than a "configuration" file, so I'd say go with Text::CSV (it allows you to choose a separator character in a constructor, so you can do colon-separated instead of comma-separated), or for very large files Text::CSV_XS.