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版)
标量数据
37
对数字进行运算的操作符(比如乘法)如果遇到字符串类型的操作数,
Perl
会自动将
字符串转换成等效的十进制浮点数进行运算。因此
"12" * "3"
的结果会是
36
。字符
串中非数字的部分(以及前置的空白符号)会被略过,所以
"12fred34" * "3"
也会得
36
,而不会出现任何警告信息(除非你要求
Perl
显示警告信息,稍后我们就会提
到有关警告信息的处理)。完全不含数字的字符串会被转换成零,比如把
"fred"
成数字来用,就是这种情况。
前导
0
的技巧只能用于八进制直接量,不能用于字符串的自动转换。请记住,自动转
换总是基于十进制数字来处理的:
0377 #
十进制数字
255
的八进制写法
'0377' #
会转换成十进制数字
377
稍后我们会介绍
oct
的用法,将字符串转换为八进制数字。
同样地,处理字符串的操作符(比如字符串连接操作符)如果得到的是数字的话,该
数字就会被转换为形式相同的字符串。比如要把字符串
Z
与“
5
乘以
7
的结果”相连
接,写起来非常简单:
"Z" . 5 * 7 #
等同于
"Z" . 35
,得
"Z35"
基本上你不用关心数字和字符串的差别(大多数时候),
Perl
会自动完成数据转换的
工作。并且更进一步地,
Perl
会记住已完成的转换,以便重复计算时不再浪费时间,
更快得到结果。
Perl
的内置警告信息
Perl
发现程序代码中有可疑之处时,可以通过警告信息提示你。从
Perl 5.6
开始,
我们可以通过编译指令启用警告机制(请注意查看所用的版本是否支持): ...
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