http://qs321.pair.com?node_id=244596


in reply to Substituting tokens into configuration values

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!