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版)
192
10
把任意一个
until
循环改写成
while
循环。不过随着时间推移,你会逐渐习惯采用简
单而自然的写法来使用
until
控制结构。
表达式修饰符
为了进一步简化代码书写,表达式后面可以接一个用于控制它行为的修饰符。比如下
面这个
if
修饰符,其实际作用相当于一个
if
语句块:
print "$n is a negative number.\n" if $n < 0;
这其实能达到和以下代码完全相同的效果,但我们省去了键入圆括号和花括号的工
作:
if ($n < 0) {
print "$n is a negative number.\n";
}
之前曾经提到,那些使用
Perl
的家伙都懒于打字。不过这个更短的版本其实也更容易
用英语读出来:
print this message if $n is less than zero
注意,即使条件表达式写在后面,它仍然会先执行。这与通常由左至右的顺序相反。
阅读
Perl
代码的方法就是学习
Perl
解释器的内部工作原理,先把语句全部读完再判
断其含义。
还有其他几个修饰符:
&error("Invalid input") unless &valid($input);
$i *= 2 until $i > $j;
print " ", ($n += 2) while $n < 10;
&greet($_) foreach @person;
以上写法都能按照我们原本的意图正常工作。换句话说,上面每一行都可以效
仿
if
修饰符示例进行改写。比如第三条可以改写成: ...
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