in reply to Substituting tokens into configuration values
I'd do it like this:
The INI
[GENERAL] scheduledb=something [SERVICE] start2=stuff ${GENERAL/scheduledb=default} etcetera
The "getter":
sub x_val { my ($ini,$sect,$key,$def)=@_; # same signature as 'val' my $val=$ini->val($sect,$key,$def); my ($sect1,$key1,$def1,$t); while ($val=~/\$\{([^}]+)\}/) { $t=$1; ($sect1,$key1,$def1)=($t=~m|^([^/]+)/([^=]+)(?:=(.*))?$|); $val=$`.(x_val($ini,$sect1,$key1,$def1)).$'; } $val; }
Notes:
- It uses pre- and post-match variables, so it will slow you regexps
- The syntax is a bit different from the one you show
- It expands recursively
- It supports in-line defaults
- I haven't tested it...
-- dakkar - Mobilis in mobile
|
---|
In Section
Seekers of Perl Wisdom