国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Perl > 正文

Perl簡(jiǎn)單變量的概念

2020-02-23 19:47:54
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

基本上,簡(jiǎn)單變量就是一個(gè)數(shù)據(jù)單元,這個(gè)單元可以是數(shù)字或字符串。
一、整型
1、整型
??PERL最常用的簡(jiǎn)單變量,由于其與其它語(yǔ)言基本相同,不再贅述。
?? 例:
?? $x = 12345;
?? if (1217 + 116 == 1333) {
?? # statement block goes here
?? }
??整型的限制:
?? PERL實(shí)際上把整數(shù)存在你的計(jì)算機(jī)中的浮點(diǎn)寄存器中,所以實(shí)際上被當(dāng)作浮點(diǎn)數(shù)看待。在多數(shù)計(jì)算機(jī)中,浮點(diǎn)寄存器可以存貯約16位數(shù)字,長(zhǎng)于此的被丟棄。整數(shù)實(shí)為浮點(diǎn)數(shù)的特例。
2、8進(jìn)制和16進(jìn)制數(shù)
? 8進(jìn)制以0打頭,16進(jìn)制以0x打頭。
? 例:$var1 = 047; (等于十進(jìn)制的39)
? $var2 = 0x1f; (等于十進(jìn)制的31)
二、浮點(diǎn)數(shù)
? 如 11.4 、 -0.3 、.3 、 3. 、 54.1e+02 、 5.41e03
? 浮點(diǎn)寄存器通常不能精確地存貯浮點(diǎn)數(shù),從而產(chǎn)生誤差,在運(yùn)算和比較中要特別注意。指數(shù)的范圍通常為-309到+308。
? 例:

? #!/usr/local/bin/perl.html" target="_blank">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字符可以出現(xiàn)在串的任何位置。
. 雙引號(hào)內(nèi)的字符串中支持簡(jiǎn)單變量替換,例如:
? $number = 11;
? $text = "This text contains the number $number.";
? 則$text的內(nèi)容為:"This text contains the number 11."

.雙引號(hào)內(nèi)的字符串中支持轉(zhuǎn)義字符
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關(guān)閉掉,如:
?$a = "T/LHIS IS A /ESTRING"; # same as "This is a STRING"

.要在字符串中包含雙引號(hào)或反斜線,則在其前加一個(gè)反斜線,反斜線還可以取消變量替換,如:
??$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進(jìn)制)或/xnn(16進(jìn)制)來(lái)表示ASCII字符,如:
??$result = "/377"; # this is the character 255,or EOF
??$result = "/xff"; # this is also 255

.單引號(hào)字符串
??單引號(hào)字符串與雙引號(hào)字符串有兩個(gè)區(qū)別,一是沒(méi)有變量替換功能,二是反斜線不支持轉(zhuǎn)義字符,而只在包含單引號(hào)和反斜線時(shí)起作用。單引號(hào)另一個(gè)特性是可以跨多行,如:
??$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ù)字的字符,則從左起至第一個(gè)非數(shù)字的字符,如:
??$result = "hello" * 5; # $result = 0
??$result = "12a34" +1; # $result = 13

.變量初始值
??在PERL中,所有的簡(jiǎn)單變量都有缺省初始值:"",即空字符。但是建議給所有變量賦初值,否則當(dāng)程序變得大而復(fù)雜后,很容易出現(xiàn)不可預(yù)料且很難調(diào)試的錯(cuò)誤。

以上就是關(guān)于Perl簡(jiǎn)單變量的概念,感謝大家的閱讀,更多內(nèi)容請(qǐng)關(guān)注武林技術(shù)頻道網(wǎng)站。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 治多县| 四平市| 祁阳县| 苍山县| 宜川县| 保定市| 忻城县| 延川县| 繁昌县| 日喀则市| 祁阳县| 泾源县| 道孚县| 青川县| 溧阳市| 丽水市| 瓦房店市| 奉化市| 五华县| 伊金霍洛旗| 凤翔县| 习水县| 阿合奇县| 如皋市| 锦州市| 横峰县| 金溪县| 安新县| 泸西县| 砀山县| 临桂县| 长丰县| 婺源县| 隆安县| 汾西县| 布尔津县| 五家渠市| 武清区| 布拖县| 唐河县| 康保县|