SYNOPSIS
Example 1
use Config::Magic;
use Data::Dumper;
$input=q{
Section 1 {
[Section 4]
#Comment style #1
//Comment style #2
;Comment style #3
Monkey:1
Monkey=>2
Monkey:=3
< Section 2 >
Foo = Bar
Baz { Bip:1
Pants==5 }
< /Section >
< Tasty Cheese="3" / >
< Section 5 >
Foo=Bippity,boppity,boo
< /Section >
}
}
#Fastest way:
$config = new Config::Magic();
print Dumper($config->parse($input));
Example 2
use Config::Magic;
use Data::Dumper;
#Arguments with sorting $ordered_hash = 1; $config = new Config::Magic("input.conf",$ordered_hash); print Dumper($config->parse); $result = $config->get_result; print Dumper($result);
OUTPUT (from second example)
'Section 1' => {
'Section 4' => {
'Monkey' => [
'1',
'2',
'3'
]
},
'Section' => [
{
'2' => {},
'Foo ' => 'Bar',
'Baz' => {
'Bip' => '1',
'Pants' => '5'
}
},
{
attribs=>5,
'Foo' => [
'Bippity',
'boppity',
'boo'
]
}
],
'Tasty' => {
'Cheese' => {
}
}
This module uses Parse::RecDescent to generate a parse tree for nearly any kind of configuration file. You can even combine files/configuration types. It understands XML, Apache-style, ini files, csv files, and pretty much everything else I could find. Just give it a file, and get a hash tree out. If it doesn't understand the file, or it isn't well formed (such as if a bracket is missing, etc), then you will get a partial result, or no result at all.
There is a single option that can be passed to this file which indicates that the resulting hash should be ordered rather than random. This is done using Tie::Hash::Indexed. You can also call "setordered" directly to change from using ordered to unordered hashes.
Product's homepage
Requirements:
· Perl