Leaning toothpick syndrome

From Wikipedia, the free encyclopedia

In programming, leaning toothpick syndrome (LTS) is the situation in which a quoted expression becomes unreadable because it contains a large number of escaped slashes ("/"), usually set off by backslashes ("\"), along with other visually similar characters such as pipes ("|"). The official Perl documentation introduced the term into wide usage; there, the phrase is used to describe regular expressions which match Unix-style path names, in which elements are separated by forward slashes. Patterns which match Uniform Resource Identifiers (URIs), which are also slash-delimited, frequently suffer from LTS as well.

As a mild 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/!