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

f

Form feed



Backspace

a

Alert (bell)

e

ESC character

33

ESC in octal

x7f

DEL in hexadecimal

cC

Ctrl-C

\

Backslash

"

Double quote

u

Force next character to uppercase

l

Force next character to lowercase

U

Force all following characters to uppercase

L

Force all following characters to lowercase

Q

Backslash all following non-alphanumeric characters

E

End U, L, or Q

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, braces, and angle brackets can be used as delimiters in their standard opening and closing pairs.

Table 4-2. Quoting syntax in Perl

Customary

Generic

Meaning

Interpolation

''

q//

Literal

No

""

qq//

Literal

Yes

''

qx//

Command

Yes

( )

qw//

Word list

No

( )

qr//

Pattern

Yes

//

m//

Pattern match

Yes

s///

s///

Substitution

Yes

y///

tr///

Translation

No

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.47.144