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版)
52
2
来构建程序的运作流程。但你要知道,如果开启警告信息,
Perl
会对未定义值的不
寻常使用发出警告,因为它猜测这种情况有可能引入意料之外的运行结果。例如复
undef
变量到另一个变量没问题,但要用
print
将它输出就会引发警告消息。
defined
函数
行输入操作符
<STDIN>
有时会返回
undef
。正常情况下,它返回的是读取的一行文
本,但若再无数据可读,例如到了文件结尾时,就返回
undef
。要判断某个字符串是
否为
undef
,可以用
defined
函数。如果是
undef
,该函数就返回假;否则,即便是
空字符串,那也是已定义值的,函数返回真:
$next_line = <STDIN>;
if ( defined($next_line) ) {
print "The input was $next_line";
} else {
print "No input available!\n";
}
如果想创建自己的
undef
值,可以直接使用同名的
undef
操作符:
$next_line = undef; #
回到虚无,仿佛从未用过
习题
下列习题的解答请参阅第
306
页上的“第
2
章习题解答”一节:
1. [5]
写一个程序,计算在半径为
12.5
时,圆的周长应该是多少。圆周长是半径的
长度乘上
2
π
(大约是
2
乘以
3.141592654
)。计算结果大约是
78.5
2. [4]
修改上题的程序,让它提示用户键入半径的长度。当用户键入
12.5
时,出来
的计算结果应该和上题相同。 ...
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