标量(单数)----单件事物 : 数字和字符串
1、数字:
所有数字的内部格式都相同。
即:整数或是浮点数 总是按“双精度浮点数”的要求保存并进行运算。
浮点数直接量:直接卸载程序源代码里的数据:
eg:1.25
??? 255.000
??? -6.5e24:负6.5乘以10的24次方
整数直接量:
eg:2001
??? 222233332323232可以表示成222_233_332_323_232
(perl允许在整数直接量里插入下划线,将若干位数分开)
非十进制的整数直接量:
八进制? --以0开头? eg:0377
十六进制--以0x开头 eg:0xff
二进制? --以0b开头 eg:0b22222110
(perl也允许在非十进制直接量里插入下划线,将若干位数分开) eg:0x50_60_70_7c
数字操作符
+ - * / %(取模)-先取整再求余? **(乘幂)
10%3=1 (10除以3的余数)
10.5%3.2=1
2**3=8
2、字符串
单引号内的字符串:
除了单引号和反斜线字符外,单引号内所有字符都代表它们自己。要表示反斜线字符前面加上一个反斜线字符
======================
print 'hello worldn';
E:perl>perl p.pl
hello worldn
=======================?
双引号内的字符串:
1)反斜杠可用来表示控制字符,或是用八进制或十六进制写法表示任何字符。
====================
print "hello worldn";
E:perl>perl p.pl
hello world
(换行)
=====================
2)变量内插:将字符串内的变量名称替换成该变量当前的值。
进行内插时,perl会尽可能使用最长且合法的变量名称。
===================================
$fred ='hello';
print "the name is $fred.n";
print "the name is $fred.n";
E:perl>perl? p.pl
the name is $fred.
the name is hello.
===================================
$fred ='hello';
print "the name is $fredsn"; ---在内插的值后面,紧跟这字母s,perl将后面的字母s当作变量名称的一部分
print "the name is $n ${fred}sn";?? ---通过花括号将变量名围起来,可以避免该问题。
E:perl>perl? p.pl
the name is
the name is? hellos
==================================
字符串操作符:.
eg:? "hello".' '."world"
字符串重复操作符:小写字母 x
eg: “fred”x3
E:perl>perl p.pl
fredfredfred
复制次数小于1时,会生成长度为0的空字符串。
3、数字与字符串之间的自动转换:取决于操作符需要什么类型的操作数 1)“12”*3?? 结果:36 2)“12fred34”*3? 结果:36 字符串中非数字的部分会被略过。如果字符串都不含数字时,字符串就转换为零。 3)“fred”*3 = 0