Escape Sequence | Description |
\a | Bell (beep) |
\b | Backspace |
\cn | The Ctrl+n character |
\e | Escape |
\E | Ends the effect of \L, \U or \Q |
\f | Form feed |
\l | Forces the next letter into lowercase |
\L | All following letters are lowercase |
\n | Newline |
\r | Carriage return |
\Q | Do not look for special pattern characters |
\t | Tab |
\u | Force next letter into uppercase |
\U | All following letters are uppercase |
\v | Vertical tab |
\L、\U、\Q功能可以由\E關(guān)閉掉,如:
$a = "T\LHIS IS A \ESTRING"; # same as "This is a STRING"
.要在字符串中包含雙引號或反斜線,則在其前加一個反斜線,反斜線還可以取消變量替換,如:
$res = "A quote \" and A backslash \\";
$result = 14;
print ("The value of \$result is $result.\n")的結(jié)果為:
The value of $result is 14.
.可用\nnn(8進制)或\xnn(16進制)來表示ASCII字符,如:
$result = "\377"; # this is the character 255,or EOF
$result = "\xff"; # this is also 255
.單引號字符串
單引號字符串與雙引號字符串有兩個區(qū)別,一是沒有變量替換功能,二是反斜線不支持轉(zhuǎn)義字符,而只在包含單引號和反斜線時起作用。單引號另一個特性是可以跨多行,如:
$text = 'This is two
lines of text
';
與下句等效:
$text = "This is two\nlines of text\n";
.字符串和數(shù)值的互相轉(zhuǎn)換
例1:
$string = "43";
$number = 28;
$result = $string + $number; # $result = 71
若字符串中含有非數(shù)字的字符,則從左起至第一個非數(shù)字的字符,如:
$result = "hello" * 5; # $result = 0
$result = "12a34" +1; # $result = 13
.變量初始值
在PERL中,所有的簡單變量都有缺省初始值:"",即空字符。但是建議給所有變量賦初值,否則當程序變得大而復雜后,很容易出現(xiàn)不可預料且很難調(diào)試的錯誤。
上一篇:詳細說明什么是Perl
下一篇:perl操作符詳細說明