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!


In reply to Re: Substituting tokens into configuration values by hiseldl
in thread Substituting tokens into configuration values by dbush

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.