Skip to Content
Raku学习手册
book

Raku学习手册

by brian d foy
October 2020
Beginner to intermediate
499 pages
9h 13m
Chinese
China Electric Power Press Ltd.
Content preview from Raku学习手册
36
2
% perl6 main-two-thingys.p6 Hamadryas perlicus
1: Hamadryas
2: perlicus
Hamadryas perlicus
是我为封面上的蝴蝶起的(非)学名。有时我会把它简
称为“
Hama
,因为这个词与“
llama
”(一种骆驼)押韵。
有时尽管你需要两个值,但是不想指定两个实参。那么可以为一些形参指定一个默
认值。可以使
=
指定默认值:
sub MAIN ( $thingy1, $thingy2 = 'perlicus' ) {
put '1: ', $thingy1;
put '2: ', $thingy2;
}
调用程序时,如果指定了两个实参,它的工作与前面一样,不过如果只指定了一个
实参,程序就会使用第二个参数的默认值:
% perl6 main-two-thingys-default.p6 Hamadryas februa
1: Hamadryas
2: februa
% perl6 main-two-thingys-default.p6 Hamadryas
1: Hamadryas
2: perlicus
有默认值的形参必须出现在没有默认值的形参后面。第
11
章中会学习更多有关参数
的内容。
练习
2.2
创建一个程序,接收
3
个命令行参数,将它们分行输出,每一行要分别编号。
为其中两个参数提供默认值。
2.2.2
提示输入值
prompt
例程会输出一个消息,要求用户提供输入。键入一些文本并按回车键之后,
prompt
会读取这个文本并将其返回。可以把这个值赋给一个变量: ...
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

可编程网络自动化

可编程网络自动化

Jason Edelman, Scott S. Lowe, Matt Oswalt
程序员学数据结构

程序员学数据结构

Posts & Telecom Press, William Smith
R深度学习权威指南

R深度学习权威指南

Posts & Telecom Press, Joshua F. Wiley
AI工程

AI工程

Chip Huyen

Publisher Resources

ISBN: 9787519848002