String Interpolation
Strings are sequences of characters. String literals
are usually delimited by either single ('
) or double ("
) quotes. Double-quoted string literals
are subject to backslash and variable interpolation, and
single-quoted strings are not (except for \'
and \\
, used to put single quotes and
backslashes into single-quoted strings). You can embed newlines
directly in your strings.
Table 4-1 lists all the backslashed or escape characters that can be used in double-quoted strings.
Table 4-1. Double-quoted string representations
Code | Meaning |
---|---|
| Newline |
| Carriage return |
| Horizontal tab |
| Form feed |
| Backspace |
| Alert (bell) |
| ESC character |
| ESC in octal |
| DEL in hexadecimal |
| Ctrl-C |
| Backslash |
| Double quote |
| Force next character to uppercase |
| Force next character to lowercase |
| Force all following characters to uppercase |
| Force all following characters to lowercase |
| Backslash all following non-alphanumeric characters |
| End |
Table
4-2 lists alternative quoting schemes that can be used in
Perl. These are useful in diminishing the number of commas and
quotes you may have to type, and they allow you not to worry about
escaping characters such as backslashes when there are many
instances in your data. The generic forms allow you to use any
non-alphanumeric, non-whitespace characters as delimiters in place
of the slash (/
). If the delimiters are single quotes, no variable interpolation is done on the pattern. Parentheses, brackets, ...
Get Perl in a Nutshell, 2nd 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.