Config::IniHashReadDeep - Loads INI config as deep hashes
use Config::IniHashReadDeep 'get_ini_file'; my $inihash = get_ini_file( $file ); # or OO style: use Config::IniHashReadDeep; use Data::Dumper; my $ini = Config::IniHashReadDeep->new( $file )->get_ini(); print Dumper($ini);
Example ini file:
[main] test=5 foo.bar=123 foo.more=77 [digits] with.counting.000=111 with.counting.001=112 with.counting.002=113 [digitsmore] with.counting.001.foo=111f with.counting.003.bar=111b
The example above will print that:
$VAR1 = { 'digitsmore' => { 'with' => { 'counting' => [ undef, { 'foo' => '111f' }, undef, { 'bar' => '111b' } ] } }, 'main' => { 'test' => '5', 'foo' => { 'bar' => '123', 'more' => '77' } }, 'digits' => { 'with' => { 'counting' => [ '111', '112', '113' ] } } };
It is a wrapper using Config::IniHash, but only for loading and it does something special; using the entries as paths, delimited by '.' and building a hash tree of it.
Exporter
Config::IniHash
my $inihash = $this->new(%options);
At least it takes a filename. For further values, please have a look into Config::IniHash
You may set a different 'delimiter'.
my \%inihash = $this->get_ini();
Returns the deep ini
my \%inihash = get_ini_file($filename);
this is not a method, but a static function, which you can also import like that:
use Config::IniHashReadDeep 'get_ini_file'; my $inihash = get_ini_file( $file );
The paths used in the ini must be delimited with dotts. But you can set an own delimiter via setting 'delimiter' in the constructor.
If you use numbers in the path elements, it will use an ARRAY instead of an HASH to place the value. Please note, that starting with high numbers or leaving gaps in numbers, causes undef entries. It will be up to you later to check wether there is a value or not.
Using numbers gives you the possibility to order entries.
Andreas Hernitscheck ahernit(AT)cpan.org
You can redistribute it and/or modify it under the conditions of LGPL.
To install Config::IniHashReadDeep, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Config::IniHashReadDeep
CPAN shell
perl -MCPAN -e shell install Config::IniHashReadDeep
For more information on module installation, please visit the detailed CPAN module installation guide.