#!/usr/local/bin/perl
$value = 9.01e+21 + 0.01 - 9.01e+21;
print ("first value is ", $value, "\n");
$value = 9.01e+21 - 9.01e+21 + 0.01;
print ("second value is ", $value, "\n");
#---------------------------------------------------------
#$ program3_3
#first value is 0
#second value is 0.01
【 字符串 】
慣用C的程序員要注意,在PERL中,字符串的末尾並不含有隱含的NULL字符,NULL字符可以出現在串的任何位置。
雙引號內的字符串中支持簡單變量替換,例如︰
$number = 11;
$text = "This text contains the number $number.";
則$text的內容為︰"This text contains the number 11."
雙引號內的字符串中支持轉義字符
Table 3.1. Escape sequences in strings.
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關閉掉,如︰
$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")
#結果為︰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
單引號字符串︰