NAME

String::Interpolate::Shell - Variable interpolation, shell style

VERSION

version 0.02

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, or y, 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().

BUGS AND LIMITATIONS

You can make new bug reports, and view existing ones, through the web interface at https://rt.cpan.org/Public/Dist/Display.html?Name=String-Interpolate-Shell.

AUTHOR

Diab Jerius <djerius@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2017 by Smithsonian Astrophysical Observatory.

This is free software, licensed under:

The GNU General Public License, Version 3, June 2007