大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> CGI专区 -> Perl教学 第二篇 简单变量

Perl教学 第二篇 简单变量

时间: 2021-07-31 作者:daque

基础上,大略变量即是一个数据单位,这个单位不妨是数字或字符串。一、整型 1、整型 perl最常用的大略变量,因为其与其它谈话基础沟通,不复赘述。例:$x = 12345;if (1217 + 116 == 1333) {# statement block goes here}整型的控制:perl本质上把平头生存你的计划机中的浮点存放器中,以是本质上被看成浮点数对于。在普遍计划机中,浮点存放器不妨存贮约16位数字,善于此的被抛弃。平头实为浮点数的惯例。2、8进制和16进制数8进制以0打头,16进制以0x打头。例:$var1 = 047; (即是十进制的39)$var2 = 0x1f; (即是十进制的31)二、浮点数 如 11.4 、 -0.3 、.3 、 3. 、 54.1e+02 、 5.41e03浮点存放器常常不许透彻地存贮浮点数,进而爆发缺点,在演算和比拟中要更加提防。指数的范畴常常为-309到+308。例:#!/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_3first value is 0second 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.单引号字符串单引号字符串与双引号字符串有两个辨别,一是没有变量替代功效,二是反斜线不扶助转义字符,而只在包括单引号和反斜线时起效率。单引号另一个个性是不妨跨多行,如:$text = 'this is twolines of text'; 与下句等效:$text = "this is two\nlines of text\n"; .字符串和数值的彼此变换例1:$string = "43";$number = 28;$result = $string + $number; # $result = 71若字符串中含有非数字的字符,则从左起至第一个非数字的字符,如:$result = "hello" * 5; # $result = 0$result = "12a34" +1; # $result = 13.变量初始值在perl中,一切的大略变量都有缺省初始值:"",即空字符。然而倡导给一切变量赋初值,要不当步调变得大而搀杂后,很简单展示不行预见且很难调节和测试的缺点。

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.