| Scalar-Quote documentation | view source | Contained in the Scalar-Quote distribution. |
Scalar::Quote - Utility functions to quote Perl strings
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";
Several subrutines to quote scalars and spot differences between strings.
Mostly useful for debugging purposes.
quote $n as a number.
returns the string conveniently enclosed in single or double quotes, escaping unprintable and quoting chars as required.
quote the beginning of $string.
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.
returns the index where the two strings start to differ or -1 if they are equal.
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.
Nothing by default.
exports quote, quote_start, quote_cut and quote_number
exports str_diffix and str_diff subrutines.
exports Q, S, N and D.
Salvador Fandiño, <sfandino@yahoo.com>
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.
| Scalar-Quote documentation | view source | Contained in the Scalar-Quote distribution. |