NAME
Scalar::Quote - Utility functions to quote Perl strings
SYNOPSIS
use Scalar::Quote ':short';
$_=pack('c',rand 127) for (@a[0..1000]);
$s1=join '', @a;
$_=pack('c',rand 127) for (@b[0..1000]);
$s2=join '', @b;
$_=pack('c',rand 127) for (@c[0..40]);
$s3=join '', @c;
print "Q(\$s1)=",Q($s1),"\n";
print "S(\$a)=",S($a),"\n";
D($s3.$s1, $s3.$s2);
print "$a is not the same as $b\n";
print N(0), N(1), N(undef), N("hello"), "\n";
ABSTRACT
Several subrutines to quote scalars and spot differences between strings.
Mostly useful for debugging purposes.
DESCRIPTION
- quote_number($n)
- N($n)
-
quote
$n
as a number. - quote($string)
- Q($string)
-
returns the string conveniently enclosed in single or double quotes, escaping unprintable and quoting chars as required.
- quote_start($string)
- S($string)
- quote_start($string, $length)
- S($string, $length)
-
quote the beginning of
$string
. - quote_cut($str, $start, $len)
-
similar to
substr($str, $start, $len)
but adds a head or/and a tail to the substring stating how many chars have been left out. - str_diffix
-
returns the index where the two strings start to differ or -1 if they are equal.
- str_diff($s1, $s2)
- str_diff($s1, $s2, $start, $len)
- D($s1, $s2)
- D($s1, $s2, $start, $len)
-
str_diff
compares two strings and creates quoted versions of them around the place where they start to differ.D($s1, $s2) and print "$a is not the same as $b\n";
In scalar context the quoted strings are stored in globals
$a
and$b
on the caller package.In list context the quoted strings are returned (
$a
and$b
are untouched).When both strings are equal, undef or the empty list is returned.
Optional arguments
$start
and$len
allow to configure the length of the quoting.$start
is the location to start the quote *after* the differences begin, so it should be a negative number.
EXPORT
Nothing by default.
EXPORT_TAGS
- :quote
-
exports
quote
,quote_start
,quote_cut
andquote_number
- :diff
-
exports
str_diffix
andstr_diff
subrutines. - : short
-
exports
Q
,S
,N
andD
.
AUTHOR
Salvador Fandiño, <sfandino@yahoo.com>
COPYRIGHT AND LICENSE
Copyright 2002-2006 by Salvador Fandiño
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.