String::Interpolate::RE - interpolate variables into strings


String-Interpolate-RE documentation  | view source Contained in the String-Interpolate-RE distribution.

Index


NAME

Top

String::Interpolate::RE - interpolate variables into strings

SYNOPSIS

Top

    use String::Interpolate::RE qw( interpolate );

    $str = strinterp( "${Var1} $Var2", \%vars, \%opts );




DESCRIPTION

Top

This module interpolates variables into strings, using the passed %vars hash as well as %ENV as the source of the values.

It uses regular expression matching rather than Perl's built-in interpolation mechanism and thus hopefully does not suffer from the security problems inherent in using eval to interpolate into strings of suspect ancestry.

INTERFACE

Top

strinterp
    $str = strinterp( $template );
    $str = strinterp( $template, \%var );
    $str = strinterp( $template, \%var, \%opts );

Interpolate variables into a template string, returning the resultant string. The template string is scanned for tokens of the form

    $VAR
    ${VAR}

where VAR is composed of one or more word characters (as defined by the \w Perl regular expression pattern). If a matching token is a key in either the optional %var hash or in the %ENV hash the corresponding value will be interpolated into the string at that point. REs which are not defined are by default left as is in the string.

The %opts parameter may be used to modify the behavior of this function. The following (case insensitive) keys are recognized:

Format

If this flag is true, the template string may provide a sprintf compatible format which will be used to generate the interpolated value. The format should be appended to the variable name with an intervening : character, e.g.

    ${VAR:fmt}

For example,

    %var = ( foo => 3 );
    print strinterp( '${foo:%03d}', \%var, { Format => 1 } );

would result in

    003




RaiseUndef

If true, a variable which has not been defined will result in an exception being raised. This defaults to false.

EmptyUndef

If true, a variable which has not been defined will be replaced with the empty string. This defaults to false.

UseENV

If true, the %ENV hash will be searched for variables which are not defined in the passed %var hash. This defaults to true.

DIAGNOSTICS

Top

undefined variable: %s

This string is thrown if the RaiseUndef option is set and the variable %s is not defined.

BUGS AND LIMITATIONS

Top

No bugs have been reported.

Please report any bugs or feature requests to bug-string-interpolate-re@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=String-Interpolate-RE.

SEE ALSO

Top

Other CPAN Modules which interpolate into strings are String::Interpolate and Interpolate. This module avoids the use of eval() and presents a simpler interface.

VERSION

Top

Version 0.01

LICENSE AND COPYRIGHT

Top

AUTHOR

Top

Diab Jerius <djerius@cpan.org>


String-Interpolate-RE documentation  | view source Contained in the String-Interpolate-RE distribution.