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版)
80
4
当然,你也可以使用
my
来创建新的私有数组:
my @phone_number;
所有新变量的值一开始都是空的:标量被设为
undef
,数组被设为空列表。
在日常
Perl
编程当中,你最好对每个新变量都使用
my
声明,让它保持在自己所在的
词法作用域内。在第
3
章中,我们看到过如何在
foreach
循环内定义自己的控制变
量,而这个控制变量也可以声明为词法变量:
foreach my $rock (qw/ bedrock slate lava /) {
print "One rock is $rock.\n"; #
依次输出每块石头的名字
}
这一点很重要,接下来的小节里,我们会全面使用这种声明变量的方式。
use strict
编译指令
Perl
是一门相当宽容的编程语言,但有时候你也许希望它能更严格些,多点约束力,
那么不妨试试看
use strict
编译指令。
所谓编译指令(
pragma
),是提供给编译器的某些指示,告诉它如何处理接下来的代
码。这里的
use strict
编译指令是要告诉
Perl
内部的编译器,接下来的代码块或程
序源文件的代码应该严谨遵循优良编程风格。
这么做的重要性何在?嗯,设想你正在写程序并键入下面这行代码:
$bamm_bamm = 3; # Perl
会自动创建这个变量
然后你继续键入了些代码。当上一行代码被新写的代码挤出屏幕顶端后,你又写了下
面这行代码,想增加那个变量的值:
$bammbamm += 1; #
糟了
!
因为
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

Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉
Perl语言入门

Perl语言入门

Randal L. Schwartz, brian d foy, Tom Phoenix

Publisher Resources

ISBN: 9787576602036