NAME
String::Interpolate::Shell -- Variable interpolation, shell style
SYNOPSIS
use String::Interpolate::Shell qw[ strinterp ];
$interpolated_text = strinterp( $text, \%var, \%attr );
DESCRIPTION
String::Interpolate::Shell interpolates variables into strings. Variables are specified using a syntax similar to that use by bash. Undefined variables can be silently ignored, removed from the string, can cause warnings to be issued or errors to be thrown.
- $varname
-
Insert the value of the variable.
- ${varname}
-
Insert the value of the variable.
- ${varname:?error message}
-
Insert the value of the variable. If it is not defined, the routine croaks with the specified message.
- ${varname:-default text}
-
Insert the value of the variable. If it is not defined, process the specified default text for any variable interpolations and insert the result.
- ${varname:+default text}
-
If the variable is defined, insert the result of interpolating any variables into the default text.
- ${varname:=default text}
-
Insert the value of the variable. If it is not defined, insert the result of interpolating any variables into the default text and set the variable to the same value.
- ${varname::format}
-
Insert the value of the variable as formatted according to the specified sprintf compatible format.
- ${varname:~op/pattern/replacement/msixpogce}
-
Insert the modified value of the variable. The modification is specified by op, which may be any of
s
,tr
, ory
, corresponding to the Perl operators of the same name. Delimiters for the modification may be any of those recognized by Perl. The modification is performed using a Perl string eval.
In any of the bracketed forms, if the variable name is preceded with an exclamation mark (!
) the name of the variable to be interpreted is taken from the value of the specified variable.
FUNCTIONS
- strinterp
-
$interpolated_text = strinterp( $template, \%var, \%attr );
Return a string containing a copy of
$template
with variables interpolated.%var
contains the variable names and values.%attr
may contain the following entries:- undef_value
-
This indicates how undefined variables should be interpolated
ignore
-
Ignore them. The token in
$text
is left as is. remove
-
Remove the token from
$text
.
- undef_verbosity
-
This indicates how undefined variables should be reported.
silent
-
No message is returned.
warn
-
A message is output via
carp()
. fatal
-
A message is output via
croak()
.
SEE ALSO
String::Interpolate, String::Interpolate::RE, String::Expand, String::MatchInterpolate.
COPYRIGHT AND LICENSE
Copyright 2011 Smithsonian Astrophysical Observatory
This is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
AUTHOR
Diab Jerius