One
major differencebetween double- and single-quoted strings
is that double-quoted strings have some special
escape sequencesthat can be used. Escape sequences represent characters that are
not easily entered using the keyboard or that are difficult to
see inside an editor window. The following are all of the escape
sequences that
Perl understands are given in Table
(W\6KyP'DO051Testing软件测试网,b7k(Kj P\*Lzc}Table 2.1:Perl Escape SequencesEscape Sequences | Description or Character |
---|
\ b | Backspace |
\ e | Escape |
\ f | Form. Feed |
\ n | Newline |
\ r | Carriage Return |
\ t | Tab |
\ v | Vertical Tab |
\ $ | Dollar Sign |
\ @ | Ampersand |
\ 0nnn | Any Octal byte |
\ xnn | Any Hexadecimal byte |
\ cn | Any Control character |
\ l | Change the next character to lowercase |
\ u | Change the next character to uppercase |
\ L | Change the following characters to |
| lowercase until a\ E |
| sequence is encountered. |
| Note that you need to use an |
| uppercase E here, lowercase |
| will not work. |
\ Q | Quote meta-characters as literals. |
\ U | Change the following characters |
| to uppercase until a\ E |
| sequence is encountered. Note that you |
| need to use an uppercase E |
| here, |
| lowercase will not work. |
\ E | Terminate the\ L,\ Q, |
| or\ U sequence. |
| Note that you need to use an |
| uppercase E here, lowercase will not
work. |
\ \ | Backslash |
`5q4Q6op9u01R2t6\;kR/x0
+y`)SHi#wT2^'X0-[Z
^1Z)Syr&j0NoteIn the next chapter we'll see why you might need to use a backslash when using the $
and @ characters.
-QuXv'qG} y0;B^/P%yWMe&?d0n051Testing软件测试网,nkcY:g4Vb
N8s Wc E0
8b5R^so2_z{AvG051Testing软件测试网o)i"b4jM*M0B3|'ExThe examples following the table
will illustrate some of them.51Testing软件测试网t#g kD)U!{%SY0]|
"\udave \umarshall is \x35\x years
)dx3aGXoP)A0old."51Testing软件测试网a8qRotaD'U`
51Testing软件测试网&jh/u#}#o"AdThis literal represents the following:Dave Marshall is 35 years old.
Y"w/OB:c6s051Testing软件测试网uU"mZ5TOThe\
u is used twice in the first word to capitalize thedandmcharacters. And the hexadecimal notation is used to represent the age using the
ASCII codes for 3 and 5.
T0u6jT8P0"The kettle was \Uhot\E!"51Testing软件测试网jk+\:g c
T3PT-oN6{B E0This literal represents the following:The kettle was HOT!.
The\
U capitalizes all characters until a\
E sequence is seen.51Testing软件测试网3?(_!i1D'Y`G
.QhTP [$q
It%D0A final example:
&[6l5w+b
M&Eop8i0print "Bill of Goods51Testing软件测试网K s5I AbVxwA
51Testing软件测试网P!A-kS3wg
P c5j}
51Testing软件测试网ULF#Ms#r
(fH"Ij%g[5W3Mc7W0Bread:\t\$34.45\n";51Testing软件测试网-LoKm8it
51Testing软件测试网Lu#EK*P5V3} {
print "Fruit:\t";51Testing软件测试网-^-jP*k@8i
51Testing软件测试网8O-H|&R
Z |"HhA
print "\$45.00\n";
6H JaF!pj051Testing软件测试网BY3{l)u#~l
print "\t======\n";51Testing软件测试网
Ksu-inG
51Testing软件测试网M!kb~t
A;L
print "\t\$79.45\n";51Testing软件测试网eQ9ss%_p
J&}GZN6q0Actually, this example isn't too difficult, but it does involve
looking at more than one literal at once and it's been a few pages
since our last advanced example. Let's look at the\
t and\
n escape
sequences.51Testing软件测试网bloC,\8pg@4} ic
pc)b.uQ t0This program uses two methods to cause a line break.
~h)Cty1fm0- The first is simply to include the line break in the source
code.
- The second is to use the
\
n or newline character.
51Testing软件测试网$d$Tw*?*VJ