Escape(3pm) User Contributed Perl Documentation Escape(3pm)
NAME
String::Escape - Backslash escapes, quoted phrase, word elision, etc.
SYNOPSIS
This module provides a flexible calling interface to some frequently-performed string conversion functions, including applying and removing
backslash escapes like
and , wrapping and removing double-quotes, and truncating to fit within a desired length.
use String::Escape qw( printable unprintable );
# Convert control, high-bit chars to
or xxx escapes
$output = printable($value);
# Convert escape sequences back to original chars
$value = unprintable($input);
use String::Escape qw( elide );
# Shorten strings to fit, if necessary
foreach (@_) { print elide( $_, 79 ) . "
"; }
use String::Escape qw( string2list list2string );
# Pack and unpack simple lists by quoting each item
$list = list2string( @list );
@list = string2list( $list );
use String::Escape qw( escape );
# Defer selection of escaping routines until runtime
$escape_name = $use_quotes ? 'qprintable' : 'printable';
@escaped = escape($escape_name, @values);
INTERFACE
All of the public functions described below are available as optional exports.
You can either import the specific functions you want, or import only the "escape()" function and pass it the names of the functions to
invoke.
Quoting
Each of these functions takes a single simple scalar argument and returns its escaped (or unescaped) equivalent.
quote($value) : $escaped
Add double quote characters to each end of the string.
unquote($value) : $escaped
If the string both begins and ends with double quote characters, they are removed, otherwise the string is returned unchanged.
quote_non_words($value) : $escaped
As above, but only quotes empty, punctuated, and multiword values; simple values consisting of alphanumerics without special characters
are not quoted.
singlequote($value) : $escaped
Add single quote characters to each end of the string.
unsinglequote($value) : $escaped
If the string both begins and ends with single quote characters, they are removed, otherwise the string is returned unchanged.
Backslash Escaping Functions
Each of these functions takes a single simple scalar argument and returns its escaped (or unescaped) equivalent.
These functions recognize common whitespace sequences "
", "
", and " ", as well as hex escapes "x4F" and ocatal "