From: "Ing. Branislav Gerzo" <[EMAIL PROTECTED]>
> it isn't of course only foo. I am parsing ini file, which looks like:
>
> [ini]
> foo=test
> bar=foo [%foo%] bar
>
> and of course, I want to get (after using some config module)
> $bar='foo test bar'
Is it really necessary to use [%foo%]? I'm not sure about others but
my Config::IniHash optionaly interpolates system variables into the
options if you have them specified like this:
[ini]
bar=foo %foo% bar
use Config::IniHash qw(ReadINI);
my $config = ReadINI( $filename,
systemvars => 1, case => 'preserve'
);
If you want to use a different set of variables to insert into the
options you just need to temporarily change %ENV:
use Config::IniHash qw(ReadINI);
my $config;
{
local %ENV = (foo => 1234, bar => 987, ...);
$config = ReadINI( $filename, systemvars => 1, case => 'preserve');
}
If you realy need to use that syntax you may use Config::IniHash's
forValue option like this:
use Config::IniHash qw(ReadINI);
my %data = ( foo => 1234, ... );
my $config = ReadINI( $filename,
systemvars => 0,
case => 'preserve',
forValue => sub {
my ($name, $value) = @_;
$value =~ s/\[%([^%]+)%\]/$data{$1}/g;
return $value;
}
);
This way the module does the INI file parsing and you can tweak the
values as they are read.
HTH, Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>