- Leaning toothpick syndrome
In
computer programming , leaning toothpick syndrome (LTS) is the situation in which a quoted expression becomes unreadable because it contains a large number ofescape character s, usuallybackslash es (""), to avoid delimiter collision.The official
Perl documentation [ [http://perldoc.perl.org/perlop.html#m%2fPATTERN%2fmsixpogc perlop - perldoc.perl.org] ] introduced the term to wider usage; there, the phrase is used to describeregular expression s that matchUnix -style paths in which the elements are separated by forward slashes.LTS appears in many programming languages and in many situations, including in patterns that match
Uniform Resource Identifier s (URIs) and in programs that output quoted text. Many quines fall into the latter category.Pattern example
Consider the following Perl regular expression intended to match URIs which identify files under the
pub
directory of an FTP site:Perl solves this problem by allowing many other characters to be delimiters for a regular expression. For example, the following three examples are equivalent to the expression given above:
m{ftp:// [^/] */pub/} m#ftp:// [^/] */pub/# m!ftp:// [^/] */pub/!
Quoted text example
A Perl program to print an HTML link tag, where the URL and link text are stored in variables
$url
and$text
respectively, might look like this. Notice the use of backslashes to escape the quoted double-quote characters:print "$text";
Using single quotes to delimit the string is not feasible, as Perl does not expand variables inside single-quoted strings.
print '$text'Using the
printf
function is a viable solution in many languages (Perl, C,PHP ):printf('%s', $url, $text);
The
qq
operator in Perl allows for any delimiter:print qq{$text}; print qq|$text|; print qq/$text/;
Here document s are especially well suited for multi-line strings; however, here documents do not allow for proper indentation. This example shows the Perl syntax:print <
ee also
*
String literal References
Wikimedia Foundation. 2010.