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

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
D!`0aS4?~!agSuSk.xl051Testing软件测试网D j0@PUPp
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

e2A:` {z051Testing软件测试网8he#Pp3mL2B

:~Y TOUM-Y{0

CG$zOW'W3JO0NoteIn the next chapter we'll see why you might need to use a backslash when using the $ and @ characters.51Testing软件测试网6gxz/D$hc+Q)M

51Testing软件测试网"VNWW7].z

^8A(qPS9a qjF051Testing软件测试网6VN^QPF:I

51Testing软件测试网,Nm0}}kO

+e2hrg(V)JT0The examples following the table will illustrate some of them.51Testing软件测试网U P @ b\d!H m[

"\udave \umarshall is \x35\x years51Testing软件测试网(X4}d t@
old."
g$B6UE'O0

e{D|"t0This literal represents the following:Dave Marshall is 35 years old.51Testing软件测试网1D-~.Y+N*Ipl

/W"V6^o F9GK3I'L0The\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.

"x SGYHH/IS;Q0
"The kettle was \Uhot\E!"
ouWg R1G0
51Testing软件测试网"a*M3K#\)YO A+EM$a

This literal represents the following:The kettle was HOT!. The\U capitalizes all characters until a\E sequence is seen.51Testing软件测试网zER*_"]1U0E\

51Testing软件测试网7EY~9`4erLg8\e

A final example:

(f["PO)`.{&n8x0
print "Bill of Goods51Testing软件测试网9{%nH-j	VP:ys#CL6Z
51Testing软件测试网_ T_:e9E;T"t6g/C)B
51Testing软件测试网:~sN V"p1o,m

I*o7W-d1z.fZ ^K0Bread:\t\$34.45\n";
(Qm(A0_7O!C0
Y2Xlm(Ub0print "Fruit:\t";51Testing软件测试网C:r4_&FbDE6c

m!_pV|\'Fj:uz0print "\$45.00\n";
0L$\%b9s@0
wO_(a j%q+G0print "\t======\n";
C/m(z;l {W!WWK051Testing软件测试网 G9D6\ M1Q B
print "\t\$79.45\n";
i F)k$R;K)F0
51Testing软件测试网HA QX4R7D!p

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

/XD ^[M"Sz051Testing软件测试网-T*of~1o,W(D

This program uses two methods to cause a line break.

7["AK\4jz {;dM:l0
  • The first is simply to include the line break in the source code.
  • The second is to use the\n or newline character.
51Testing软件测试网Ezf wN&[

TAG:

 

评分:0

我来说两句

Open Toolbar