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.
$nas a number.
returns the string conveniently enclosed in single or double quotes, escaping unprintable and quoting chars as required.
- quote_start($string, $length)
- S($string, $length)
quote the beginning of
- quote_cut($str, $start, $len)
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($s1, $s2)
- str_diff($s1, $s2, $start, $len)
- D($s1, $s2)
- D($s1, $s2, $start, $len)
str_diffcompares 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
$bon the caller package.
In list context the quoted strings are returned (
When both strings are equal, undef or the empty list is returned.
$lenallow to configure the length of the quoting.
$startis the location to start the quote *after* the differences begin, so it should be a negative number.
Nothing by default.
- : short
Salvador Fandiño, <email@example.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.