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
Post a Comment