Leaning toothpick syndrome

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 of escape characters, usually backslashes (""), 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 describe regular expressions that match Unix-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 Identifiers (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:

m/ftp:// [^/] */pub//

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 documents 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.

Игры ⚽ Нужна курсовая?

Look at other dictionaries:

  • Escape character — In computing and telecommunication, an escape character is a character which invokes an alternative interpretation on subsequent characters in a character sequence. An escape character is a particular case of metacharacters. Generally, the… …   Wikipedia

  • String literal — A string literal is the representation of a string value within the source code of a computer program. There are numerous alternate notations for specifying string literals, and the exact notation depends on the individual programming language in …   Wikipedia

  • Delimiter — This article is about delimiters in computing. For delimiters in written human languages, see interword separation. A stylistic depiction of a fragment from a CSV formatted text file. The commas (shown in red) are used as field delimiters. A… …   Wikipedia

  • LTS — can refer to:*Learning and Teaching Scotland *Leaning Toothpick Syndrome *Low threshold spiking a spike firing characteristic of neurons *Labelled transition system an abstract machine used in the study of computation. *The London, Tilbury and… …   Wikipedia

  • LTS — Die Abkürzung LTS steht für: Lokomotivfabrik Luhansk, die größte Lokomotivfabrik in Europa Long Term Support (engl., Langzeitunterstützung), in der Softwarebranche gebräuchlicher Begriff für Softwareversionen mit langer Produktunterstützung… …   Deutsch Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”