Skip to Content
Perl语言入门(第8版)
book

Perl语言入门(第8版)

by Randal L. Schwartz, brian d foy, Tom Phoenix
October 2022
Beginner to intermediate
390 pages
7h 5m
Chinese
Southeast University Press
Content preview from Perl语言入门(第8版)
30
2
数字
虽然标量不外乎数字和字符串这两种情况,但我们还是分别讨论,这样比较容易厘清
头绪。我们先讨论数字类型的标量,然后再来讨论字符串类型的标量。
所有数字的内部格式都相同
实际上,
Perl
处理数字时用的是底层
C
库,且统一使用双精度浮点值来存储数据。
我们不用关心内部具体的处理和转换方式,但要知道这个依赖关系,所以编译与安
Perl
的时候,选择了怎样的编译参数决定了最终
Perl
能达到的计算精度和大小范
围,这是由底层库决定的,而不是
perl
解释器本身的限制。但
Perl
会在做数学计算
时根据当前平台和库做最大限度的优化,以便快速运行。
后续章节中你会看到定义整型数字(不带小数点的数字,比如
255
2 001
)和浮点
数字(带小数点的数字,比如
3.141 59
或者
1.35
×
1 025
)的具体方式。但就内部而
言,
Perl
都将它们统一转换为双精度浮点值来存储和计算。
也就是说,
Perl
内部是没有整型值的,程序中的整型常量本质上还是双精度浮点值。
所以在
Perl
里面,数字就是数字,不像其他语言,还要你事先确定数字的大小和类
型。
整数直接量
所谓直接量(
literal
),就是在源代码中直接写成数据内容的形式。直接量不是某项
计算的结果,也不是某次
I/O
操作后的结果,它是你直接写入程序代码的数据内容。
整数直接量的定义相当直白,写法如下:
0
2001
-40
137
61298040283768
最后一个数字读起来有些费力。
Perl
允许你在整数直接量中加入下划线,将若干位数 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉
Perl语言入门

Perl语言入门

Randal L. Schwartz, brian d foy, Tom Phoenix

Publisher Resources

ISBN: 9787576602036