听烂漫音乐,看美丽世界,过精彩生活……

Perl - study note - single & double quoted string

上一篇 / 下一篇  2009-05-29 23:10:50 / 个人分类:Perl

Onemajor differencebetween double- and single-quoted strings is that double-quoted strings have some specialescape 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(K j P\*Lzc}
Table 2.1:Perl Escape Sequences
Escape SequencesDescription or Character
\bBackspace
\eEscape
\fForm. Feed
\nNewline
\rCarriage Return
\tTab
\vVertical Tab
\$Dollar Sign
\@Ampersand
\0nnnAny Octal byte
\xnnAny Hexadecimal byte
\cnAny Control character
\lChange the next character to lowercase
\uChange the next character to uppercase
\LChange 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.
\QQuote meta-characters as literals.
\UChange 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.
\ETerminate the\L,\Q,
 or\U sequence.
 Note that you need to use an
 uppercase E here, lowercase will not work.
\\Backslash

`5q4Q6op9u0

1R2t6\;k R/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:g4V b

N8sWc E0

8b5R ^so2_z {AvG051Testing软件测试网o)i"b4jM*M0B3|'Ex

The examples following the table will illustrate some of them.51Testing软件测试网t#g kD)U!{%SY0]|

"\udave \umarshall is \x35\x years
)dx3aGXoP)A0old."51Testing软件测试网a8qRot aD'U `
51Testing软件测试网&jh/u#}#o"A d

This literal represents the following:Dave Marshall is 35 years old.

Y"w/OB:c6s051Testing软件测试网uU"mZ5TO

The\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&Eop8i0
print "Bill of Goods51Testing软件测试网K	s5I	AbVxwA
51Testing软件测试网P!A-kS3wg P c5j}
51Testing软件测试网ULF#Ms#r

(fH"Ij%g3Mc7W0Bread:\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!k b~t A;L
print "\t\$79.45\n";51Testing软件测试网e Q9ss%_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

TAG:

 

评分:0

我来说两句

Open Toolbar