General...rpolated(3)
π NAME π
okay bestie, welcome to the General...rpolated(3) page from User Contributed Perl Documentation β the actual module is Config::General::Interpolated, and its whole thing is: parse variables within Config files. slay. β¨
β¨ SYNOPSIS β¨
use Config::General;
$conf = Config::General->new(
-ConfigFile => 'configfile',
-InterPolateVars => 1
);
π¦ DESCRIPTION π¦
This is an internal module which makes it possible to interpolate Perl style variables in your config file (i.e. $variable or "${variable}"). π
Normally you don't call it directly β it's giving behind-the-scenes main character energy, no cap.
π VARIABLES π
Variables can be defined everywhere in the config and can be used afterwards as the value of an option. But bestie, hear me: variables cannot be used as keys or as part of keys. periodt.
If you define a variable inside a block or a named block then it is only visible within this block or within blocks which are defined inside this block. Well β let's take a look at an example:
# sample config which uses variables
basedir = /opt/ora
user = t_space
sys = unix
<table intern>
instance = INTERN
owner = $user # "t_space"
logdir = $basedir/log # "/opt/ora/log"
sys = macos
<procs>
misc1 = ${sys}_${instance} # macos_INTERN
misc2 = $user # "t_space"
</procs>
</table>
This will result in the following structure:
{
'basedir' => '/opt/ora',
'user' => 't_space'
'sys' => 'unix',
'table' => {
'intern' => {
'sys' => 'macos',
'logdir' => '/opt/ora/log',
'instance' => 'INTERN',
'owner' => 't_space',
'procs' => {
'misc1' => 'macos_INTERN',
'misc2' => 't_space'
}
}
}
So as you can see, the variable sys has been defined twice. Inside the <procs> block, ${sys} has been used, and it gets interpolated into the value of sys defined inside the <table> block β not the sys variable one level above. If sys were not defined inside the <table> block, then the "global" variable sys would have been used instead, with the value of "unix". π
Variables inside double quotes will be interpolated, but variables inside single quotes will not be interpolated. This is the same behavior as you know of Perl itself β iykyk. π«Ά
In addition, you can surround variable names with curly braces to avoid misinterpretation by the parser. iconic.
π NAMING CONVENTIONS π
Variable names must:
- start with a US-ASCII letter (
a-zorA-Z) or a digit (0-9). - contain only US-ASCII letter (
a-zorA-Z), digits (0-9), the dash (-), colon (:), dot (.), underscore (_) and plus (+) characters.
For added clarity, variable names can be surrounded by curly braces. β¨
π SEE ALSO π
Config::Generalβ the reference, the icon, the blueprint. π
π AUTHORS π
- Thomas Linden
<tlinden |AT| cpan.org> - Autrijus Tang
<autrijus@autrijus.org> - Wei-Hon Chen
<plasmaball@pchome.com.tw>
absolute legends, fr fr. π«Ά
π COPYRIGHT π
Copyright 2001 by Wei-Hon Chen <plasmaball@pchome.com.tw>. Copyright 2002-2022 by Thomas Linden <tlinden |AT| cpan.org>.
This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.
See <http://www.perl.com/perl/misc/Artistic.html>.
β VERSION β
2.16 β periodt. π
cute little sign-off, bestie π footer tea: perl v5.42.0, 2025-01-09, and the footer title General...rpolated(3) β go off and interpolate responsibly π§
π¦ where this page comes from
- opensuse-leap 16.0: perl-Config-General 2.670.0-160000.2.2 Β· Artistic-2.0
- opensuse-leap 16.0: perl-Config-General 2.670.0-160000.2.2 Β· Artistic-2.0
- opensuse-leap 16.0: perl-Config-General 2.670.0-160000.2.2 Β· Artistic-2.0
- opensuse-leap 16.0: perl-Config-General 2.670.0-160000.2.2 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms