Skip to Content
Perl语言入门
book

Perl语言入门

by Randal L. Schwartz, brian d foy, Tom Phoenix
August 2018
Beginner to intermediate
382 pages
7h 14m
Chinese
Southeast University Press
Content preview from Perl语言入门
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!
虽然这里称之为调用(
invocation
)子程序,但我们更习惯称之为呼叫(
call
)子程
序。本章会陆续介绍其他呼叫子程序的方式。
返回值
子程序被调用时一定是作为表达式的某个部分,即使该表达式的求值结果不会被用 ...
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

计算机科学导论:跨学科方法

计算机科学导论:跨学科方法

罗伯特 塞奇威克, 凯文 韦恩
Perl语言入门(第8版)

Perl语言入门(第8版)

Randal L. Schwartz, brian d foy, Tom Phoenix

Publisher Resources

ISBN: 9787564177911