我想制作一个包含一些对象的配置文件,像这样(当然没有任何参数可以被视为主键)
param1=abc
param2=ghj
param1=bcd
param2=hjk
; always the sames parameters
这个文件可以被读取,比方说Config::IniFiles
,因为它直接转录成 ini 文件,像这样
[0]
param1=abc
param2=ghj
[1]
param1=bcd
param2=hjk
例如,类似的东西
perl -pe 'if (m/^\s*$/ || !$section ) print "[", ($section++ || 0) , "]"'
并以
open my $fh, '<', "/path/to/config_file.ini" or die $!;
$cfg = Config::IniFiles->new( -file => $fh );
(...parse here the sections starting with 0.)
但是,我在这里问我一些关于事情变得相当复杂的问题......
(A) 有没有办法转换 $fh,以便在顺序读取文件之前不需要执行 perl one-liner?因此,在 perl 期间转换文件实际上是在读取它。
或者
(B) 是否有一个模块可以读取我的奇妙平面数据库?或者有什么接近的?我让 myslef 说,Gnu coreutils 会读取这种平面文件,但我不记得是怎么做的了。