Perl how to parse INI files that contains variables? -


an ini file can have variables inside like:

[section1] root=/path/to/dir home=%(root)s/my_home_dir/ 

now, perl library config::inifiles doesn't seems parse it, passes raw strings

my $result = tie %info, 'config::inifiles', ( -file => $ini_file ); 

in python there's similar package called configparser.rawconfigparser - won't convert variables, can use configparser.configparser , will.

is there similar in perl, or fix i'm looking ?

if can't find existing parser config file format using, use

sub get_conf {    ($hash, $key) = @_;    $val = $hash{key};    return undef if !defined($val);     $val =~ s{%\(([^()]*)\)}{ get($hash, $1) // "" }eg;    return $val; }  $home = get_conf(\%conf, 'home'); 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -