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

′′

q//

Literal string

No

9

″″

qq//

Literal string

Yes

9

``

qx//

Command execution

Yes

9

()

qw//

Word list

No

9

//

m//

Pattern match

Yes

37

s///

s///

Pattern substitution

Yes

38

y///

tr///

Character translation

No

38

″ ″

qr//

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:

\a

ASCII Alarm (bell).

\b

ASCII Backspace.

\e

ASCII Escape.

\f

ASCII Formfeed.

\n

ASCII Newline.

\r

ASCII Return.

\t

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

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.