Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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":



  • 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 or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2022-06-30 10:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (97 votes). Check out past polls.

    Notices?