开发者

What is the best way to make a simple Perl config file?

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 开发者_Python百科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.


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.


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜