1General::Interpolated(3U)ser Contributed Perl DocumentatiGoenneral::Interpolated(3)
2
3
4
6 Config::General::Interpolated - Parse variables within Config files
7
9 use Config::General;
10 $conf = Config::General->new(
11 -ConfigFile => 'configfile',
12 -InterPolateVars => 1
13 );
14
16 This is an internal module which makes it possible to interpolate Perl
17 style variables in your config file (i.e. $variable or "${variable}").
18
19 Normally you don't call it directly.
20
22 Variables can be defined everywhere in the config and can be used
23 afterwards as the value of an option. Variables cannot be used as keys
24 or as part of keys.
25
26 If you define a variable inside a block or a named block then it is
27 only visible within this block or within blocks which are defined
28 inside this block. Well - let's take a look to an example:
29
30 # sample config which uses variables
31 basedir = /opt/ora
32 user = t_space
33 sys = unix
34 <table intern>
35 instance = INTERN
36 owner = $user # "t_space"
37 logdir = $basedir/log # "/opt/ora/log"
38 sys = macos
39 <procs>
40 misc1 = ${sys}_${instance} # macos_INTERN
41 misc2 = $user # "t_space"
42 </procs>
43 </table>
44
45 This will result in the following structure:
46
47 {
48 'basedir' => '/opt/ora',
49 'user' => 't_space'
50 'sys' => 'unix',
51 'table' => {
52 'intern' => {
53 'sys' => 'macos',
54 'logdir' => '/opt/ora/log',
55 'instance' => 'INTERN',
56 'owner' => 't_space',
57 'procs' => {
58 'misc1' => 'macos_INTERN',
59 'misc2' => 't_space'
60 }
61 }
62 }
63
64 As you can see, the variable sys has been defined twice. Inside the
65 <procs> block a variable ${sys} has been used, which then were
66 interpolated into the value of sys defined inside the <table> block,
67 not the sys variable one level above. If sys were not defined inside
68 the <table> block then the "global" variable sys would have been used
69 instead with the value of "unix".
70
71 Variables inside double quotes will be interpolated, but variables
72 inside single quotes will not interpolated. This is the same behavior
73 as you know of Perl itself.
74
75 In addition you can surround variable names with curly braces to avoid
76 misinterpretation by the parser.
77
79 Config::General
80
82 Thomas Linden <tlinden |AT| cpan.org>
83 Autrijus Tang <autrijus@autrijus.org>
84 Wei-Hon Chen <plasmaball@pchome.com.tw>
85
87 Copyright 2001 by Wei-Hon Chen <plasmaball@pchome.com.tw>. Copyright
88 2002-2014 by Thomas Linden <tlinden |AT| cpan.org>.
89
90 This program is free software; you can redistribute it and/or modify it
91 under the same terms as Perl itself.
92
93 See <http://www.perl.com/perl/misc/Artistic.html>
94
96 2.15
97
98
99
100perl v5.30.1 2020-01-29 General::Interpolated(3)