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语言入门
88
4
say "defaults: @defaults";
say "default_end: @default_end";
运行结果如下,可以看到没有参数时是按照默认值运行的:
defaults: 0 1 2 3 4 5 6 7
default_end: 17 16 15 14 13 12 11 10 9 8 7
有时候我们需要某些可选参数,无需默认值,那么用
$=
占位符表示即可:
sub one_or_two_args ( $first, $= ) { ... }
其实
$=
Perl
的一个特殊变量,用于控制格式化文本,但在这里不会造成歧义,所
以借用这个形式。具体有关格式化的内容,这里不作展开。
有时候我们需要以无参数的方式使用子程序,比如一个返回常量值的子程序:
sub PI () { 3.1415926 }
可以阅读
perlsub
文档了解更多关于签名的内容。我们也为此特性写过一篇博客文章
《使用
v5.20
的子程序签名》(
http://www.effectiveperlprogramming.com/2015/04/use-
v5-20-subroutine-signatures/
)。
由于这是实验特性,将来可能会有改动。建议在生产系统中务必谨慎小心使用。
习题
以下习题答案参见第
304
页上的“第
4
章习题解答”一节:
1. [12]
写一个名为
total
的子程序,它可以返回给定列表中数字相加的总和。提
示:该子程序不需要执行任何
I/O
,它只需要按要求处理它的参数并给调用者返 ...
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