If you are not stuck using Config::IniFile and can switch to Config::General, then you get variable substitution built in.
use Config::General;
use Data::Dumper;
$conf = new Config::General(
-ConfigFile => 'y.cfg',
-InterPolateVars => 1,
);
my %config = $conf->getall;
print Dumper(\%config);
__END__
# config file contents
# GENERAL
# scoping allows substituting in the same block or
# a nested block, see N.B. below.
scheduledb=e:\users\dbush\schedule.db
<SERVICE>
debug=1
interval=5
start1=browser.exe;browser;NORMAL_PRIORITY_CLASS
start2=schedule.exe;schedule "localhost:$scheduledb";NORMAL_PRIORITY_C
+LASS
</SERVICE>
########### Output: $VAR1 = \%config
### note how $scheduledb is substituted into 'start2'
$VAR1 = {
'SERVICE' => {
'start1' => 'browser.exe;browser;NORMAL_PRIOR
+ITY_CLASS',
'start2' => 'schedule.exe;schedule "localhost
+:e:\\users\\dbush\\schedule.db";NORMAL_PRIORITY_CLASS',
'interval' => '5',
'debug' => '1'
},
'scheduledb' => 'e:\\users\\dbush\\schedule.db'
};
N.B. One thing to watch out for is scoping your name-value pairs. For all the details about scoping for interpolation, check out Config::General::Interpolated.
-- hiseldl What time is it? It's Camel Time!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|