听烂漫音乐,看美丽世界,过精彩生活……
Perl - study note - single & double quoted string
上一篇 /
下一篇 2009-05-29 23:10:50
/ 个人分类:Perl
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
D!`0aS4?~!agSuSk.xl051Testing软件测试网D
j0@PUPpTable 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 |
e2A:`
{z051Testing软件测试网8he#Pp3mL2B:~ YTOUM-Y{0CG$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:I51Testing软件测试网,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!"
ouWgR1G0
51Testing软件测试网"a*M3K#\)YO
A+EM$aThis 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\eA final example:
(f ["PO)`.{&n8x0print "Bill of Goods51Testing软件测试网9{%nH-j VP:ys#CL6Z
51Testing软件测试网_T_:e9E;T"t6g/C)B
51Testing软件测试网:~sN V"p1o,m
I*o7W-d1z.f Z^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_(aj%q+G0print "\t======\n";
C/m(z;l {W!WWK051Testing软件测试网 G9D6\ M1Q B
print "\t\$79.45\n";
iF)k$R;K)F0
51Testing软件测试网HA QX4R7D!pActually, 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(DThis 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软件测试网Ezfw N&[
收藏
举报
TAG: