Skip to Content
Perl语言入门
book

Perl语言入门

by Randal L. Schwartz, brian d foy, Tom Phoenix
August 2018
Beginner to intermediate
382 pages
7h 14m
Chinese
Southeast University Press
Content preview from Perl语言入门
46
2
2
-
2
:操作符的结合性与优先级(从高至低排序)(续)
结合性
操作符
?:
(条件操作符)
= += -= .=
(以及类似的赋值操作符)
, =>
列表操作符(向右结合)
not
and
or xor
在这个表格里,任何操作符的优先级都高于列在它下方的所有操作符,并低于列在它
上方的所有操作符。如果操作符间的优先级相同,则按照结合性的规则来判断。
当两个优先级相同的操作符抢着使用三个操作数时,优先级便交由结合性解决:
4 ** 3 ** 2 # 4 ** (3 ** 2)
,得
4 ** 9
(向右结合)
72 / 12 / 3 # (72 / 12) / 3
,得
6/3
,得
2
(向左结合)
36 / 6 * 3 # (36 / 6) * 3
,得
18
在第一个例子里,因为
**
操作符是向右结合的,所以隐含的括号放在右边;
*
/
是向左结合的,因此隐含的括号放在左边。
是不是该把优先级表背下来呢?不!没人会这么做。要是记不起顺序又懒得查表,直
接用括号明确就是了。毕竟,要是你在没有括号的情况下会忘记顺序,那么维护程序
的人也会遇到相同的麻烦。所以,还是对他好一点吧:说不定将来那个人就是你自
己。
比较操作符
比较数字大小时,
Perl
的比较操作符类似于代数系统:
<
<=
==
>=
>
!=
这个是符合我们常规逻辑的。这些操作符的返回值要么是真(
true
),要么是假
false
),我们将会在下一节详细讨论这些返回值的含义。这些操作符在
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

计算机科学导论:跨学科方法

计算机科学导论:跨学科方法

罗伯特 塞奇威克, 凯文 韦恩
Perl语言入门(第8版)

Perl语言入门(第8版)

Randal L. Schwartz, brian d foy, Tom Phoenix

Publisher Resources

ISBN: 9787564177911