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版)
其他控制结构
191
if ( ! ($fred =~ /\A[A-Z_]\w*\z/i) ) {
print "The value of \$fred doesn't look like a Perl identifier name.\n";
}
一般来说,我们应该选择最容易理解的方法写代码。对程序维护员来说,读得越顺,
理解起来也就越容易。如果用
if
表达比较拗口,加上否定才通顺的话,那就应该改
unless
。以后你就会发现,有时候只有使用
unless
才更自然。
伴随
unless
else
子句
其实
unless
结构也可以使用
else
子句。不过这种语法写出来比较容易叫人皱眉:
unless ($mon =~ /\AFeb/) {
print "This month has at least thirty days.\n";
} else {
print "Do you see what's going on here?\n";
}
确实有人希望能这么写,特别当第一个子句相当短(也许只有一行)而第二个子句又
有很多行的时候。不过我们可以把它改写成取反操作的
if
语句,或者干脆对调两个
代码块成为一个普通
if
控制结构:
if ($mon =~ /\AFeb/) {
print "Do you see what's going on here?\n";
} else {
print "This month has at least thirty days.\n";
}
有一点很重要,请记住,代码的读者永远可以分为两类:执行代码的机器以及维护代 ...
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