简体   繁体   English

读取/写入perl对象配置文件

[英]read / write perl object config files

I'm looking for a perl config file editor. 我正在寻找一个perl配置文件编辑器。 I see some great mods like: 我看到一些很棒的mod,例如:

Config::General Config ::常规

Config::Simple Config :: Simple

Config::Tiny Config :: Tiny

However, these options tend to load ini, yaml, json, etc.. files instead of perl config files. 但是,这些选项倾向于加载ini,yaml,json等文件,而不是perl配置文件。

Wouldn't it always be faster and safer in perl to load a perl config file? 在perl中加载perl配置文件是否总是更快,更安全? That way the file is loaded through an eval or do instead of parsed manually through reg exps etc. However I can't seem to find a good prewritten version of this. 这样,文件就可以通过eval加载或执行,而不是通过reg exps等手动解析。但是,我似乎找不到一个好的预写版本。

Reading and Writing Perl... - old perlmonks thread 读写Perl ...-旧的perlmonks线程

OpenPlugin::Config::Perl - potentially what i'm looking for ?? OpenPlugin :: Config :: Perl-可能是我正在寻找的??

What is the best module to use? 最好使用什么模块? Is there a reason ini file loading seems to be more popular than loading a file directly in the language it is already written in? 加载ini文件似乎比直接使用已编写的语言直接加载文件更受欢迎吗?

Thanks 谢谢

UPDATE 更新

I would not be evaluating a random file, I will be loading my own custom perl file. 我不会评估随机文件,而是将加载自己的自定义perl文件。 This would be the same thing as loading a php config file already written in php. 这与加载已经用php编写的php配置文件是一样的。 Anyone know of a module that uses PERL? 有人知道使用PERL的模块吗?

Unless we're talking about gigantic config files, I wouldn't worry about the speed of loading and parsing a config file. 除非我们谈论的是巨大的配置文件,否则我不会担心加载和解析配置文件的速度。

Regarding safety, you wouldn't want to just eval any old Perl code / config that you'd read from the filesystem - who knows what it will try to do? 关于安全性,您不希望eval从文件系统读取的任何旧的Perl代码/配置-谁知道它将尝试做什么? You'd want to make sure to use the reval method from the Safe module. 您需要确保使用“ 安全”模块中的reval方法。

The project I'm working on at the moment uses Config::Any. 我目前正在处理的项目使用Config :: Any。 It's fairly easy to use and is very flexible with which types of config files that it will accept (On the synopsis it says it uses yaml, json, ini, among other ones). 它相当容易使用,并且可以接受哪种配置文件类型(在提要中说它使用yaml,json,ini等)非常灵活。

In my experience using JSON or yaml seems to do the trick but I'm not well versed in the pros and cons of using each one so you'll have to decide that for yourself :). 根据我的经验,使用JSON或yaml似乎可以解决问题,但是我不太了解每种方法的优缺点,因此您必须自己决定:)。 Hope that helped ^^ 希望对你有帮助^^

eval ing a random config file as Perl is fraught with danger. 由于Perl充满危险,因此eval一个随机的配置文件。 It could have anything in it, including code to wipe your hard drive. 它可能包含任何内容,包括擦除硬盘的代码。 It also weakens locality of reference because you have executable code that's affecting the overall state of your program outside your program. 它还会削弱引用的局部性,因为您的可执行代码会影响程序外部程序的整体状态。

For configuration files, I often use XML::Simple. 对于配置文件,我经常使用XML :: Simple。 It's an easy way of getting basic name-value pairs. 这是获取基本名称/值对的简单方法。

I don't think Config::Any provides Read+Write. 我不认为Config :: Any提供读+写功能。

But if you are willing to work with Perl Data Structure for config as there are some arguments against JSON etc - you may want ot take a look at Config::Perl 但是,如果您愿意使用Perl数据结构进行配置,因为存在一些反对JSON的参数,那么您可能希望ot看看Config :: Perl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM