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版)
72
4
出现在开头部分。你可以随意选择采用哪种风格。不管怎样,你都不需要对子程序进
行事先声明。子程序的定义是全局的,除非你使用一些强有力的技巧,否则不存在所
谓的私有子程序。假如你定义了两个重名的子程序,那么后面的子程序会覆盖掉前面
的那个。如果启用了警告功能,
Perl
会告诉你有子程序被重复定义。一般来说,重名
总归是不够妥当的做法,也会让程序维护员感到困惑。
我们不会深入讨论不同包内的同名子程序,但我们的另一本书
Intermediate
Perl
中会有说明。
正如你在之前的例子中看到的,你可以在子程序主体中使用任何全局变量。事实上
,
目前你见过的所有变量都是全局的。这就是说,你可以在你的程序的任何位置访问这
些变量。很多语言学的好事者可能会为此感到震惊,但
Perl
开发组很多年前就组织了
一众手持火把的愤青,把这些好事者赶出群。我们稍后会在“子程序中的私有变量”
一节中学到如何建立私有变量。
调用子程序
在任意表达式中,子程序名前加上
&
就表示调用这个子程序:
&marine; #
打印
Hello, sailor number 1!
&marine; #
打印
Hello, sailor number 2!
&marine; #
打印
Hello, sailor number 3!
&marine; #
打印
Hello, sailor number 4!
通常,我们称之为调用(
calling
)子程序。本章会陆续介绍其他调用子程序的方式。
返回值
子程序被调用时一定是作为表达式的某个部分,即使该表达式的求值结果不会被用 ...
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