[英]Representing a complex Perl data structure containing array references in Config::General
我在Perl代碼中具有以下數據結構:
my $config = {
'View::Mason' => {
comp_root => [
[ 'teamsite' => 'root/teamsite' ],
[ 'components' => 'root/components' ],
],
},
};
我正在嘗試在Config :: General配置文件中表示此結構。
到目前為止,我有:
<View::Mason>
<comp_root>
teamsite root/teamsite
</comp_root>
<comp_root>
components root/components
</comp_root>
</View::Mason>
這至少使“ comp_root”元素成為數組引用,但是我無法使其指向另一個數組引用。
可以在Config :: General中完成嗎?
我認為Config :: General不可能實現。 例如:
use Config::General qw(SaveConfigString);
my $config = {
'View::Mason' => {
comp_root => [
[ 'teamsite' => 'root/teamsite' ],
[ 'components' => 'root/components' ],
],
},
};
print SaveConfigString($config);
產生
<View::Mason>
comp_root ARRAY(0x94ea168)
comp_root ARRAY(0x94fbc98)
</View::Mason>
如果無法保存,則可能無法加載。
這就是我要做的:
YAML可能是您的選擇:
use strict;
use warnings;
use Data::Dumper qw(Dumper);
use YAML::XS qw(Load);
my $config_text = '
View::Mason:
comp_root:
-
- teamsite
- root/teamsite
-
- components
- root/components
';
my $config = Load($yaml_text);
print Dumper($config);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.