Chapter 6. Quotes and Interpolation
Perl uses customary quotes to construct strings and such, but also implements a generic quoting mechanism. In the following table q//
means that anything placed between the slashes is treated as if it were placed between single quotes, but it also means that you may use any nonalphanumeric, nonspace character instead of the slashes. Grouping characters like (), {}, [],
and <>
must be used in pairs.
When the quoting mechanism involves three delimiters you can also use two pairs of grouping characters, e.g., s{ ... }[ ... ]
.
Customary | Generic | Meaning | Inter. | Page |
---|---|---|---|---|
|
| Literal string | No | 9 |
|
| Literal string | Yes | 9 |
|
| Command execution | Yes | 9 |
|
| Word list | No | 9 |
|
| Pattern match | Yes | 37 |
|
| Pattern substitution | Yes | 38 |
|
| Character translation | No | 38 |
|
| Regular expression | Yes | 8 |
The “Inter.” column of the table above indicates whether string escape sequences are interpolated. If single quotes are used as delimiters for pattern matching or substitution, no interpolation takes place.
String escape sequences:
| ASCII Alarm (bell). |
| ASCII Backspace. |
| ASCII Escape. |
| ASCII Formfeed. |
| ASCII Newline. |
| ASCII Return. |
| ASCII Tab. |
Combining prefixes construct characters, for example:
\53
Interpreted as octal. This is an ASCII
+
. Octal escapes take up to three octal digits, including leading zeros. The resulting value must not exceed 377 octal. In patterns, which are like qq// strings, leading zeros are mandatory in octal escapes to avoid interpretation as a back-reference unless ...
Get Perl Pocket Reference, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.