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学习手册
基本代码块
95
{
my $n = 2;
my $m = 3;
put 'The sum is ';
put $n + $m;
}
Block
内的代码不会改变这个
Block
外的同名变量。下面的例子中,在
Block
之外(外
部作用域)有一些变量。裸
Block
中重用了同样的变量名:
my $n = 2;
my $m = 3;
{
my $n = 'Hamadryas';
my $m = 'perlicus';
put "$n $m"; # Hamadryas perlicus
}
put "n $n m $m"; # n 2 m 3
通过限定作用域,会让你如释重负,当你选择只在一小段代码中使用的变量名时,
不再需要知道整个程序中的每一个变量名。这样一来,你可以选择对当前任务最有
意义的名字,而不用担心代码的其他部分也使用了同样的名字。
5.1.2
控制结构
Block
没有相应的控制关键字。可以在一个
Block
前面加
loop
,反复地调用,永
远执行下去:
my $n = 0;
loop {
put $n++;
}
这个
loop
控制了如何执行这个
Block
。由于你没有特别说明,所以它会一直循环下去,
直到永远。
在你的职业生涯中,有时可能会不小心创建一个无限循环。你可能坐在那
里看着屏幕,心里奇怪为什么什么也没有发生。在这种情况下,可以用
Control-C
中断(停止)你的程序。
96
5
循环前面有一个声明
$n
的语句,这不是很漂亮。通常你希望只在循环内部使用这个
变量,不过,如果用
my
声明这个变量,每次执行 ...
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