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学习手册
182
8
练习
8.9
创建一个程序,向标准输出写些东西。运行这个程序,将输出重定向到一个文件。
再次运行,将输出重定向到
null
设备。
8.4.2
标准错误
标准错误是另一个输出途径。程序不希望警告和其他消息影响正常输出时,通常会
使用标准错误来输出这些警告和消息。你可以得到警告,而不会搅乱你的格式输出。
warn
会把它的消息输出到标准错误,你的程序继续执行。顾名思义,这个方法就是
要在你遇到某种能预期的情况,而且你认为应该有人了解这种情况时给出警告:
warn 'You need to use a number between 0 and 255';
fail
die
也类似。它们把消息发送到标准错误,不过还可以停止你的程序,除非
你捕获或处理了这些错误。
note
类似于
say
,它对其参数调用
.gist
,将结果输出到标准错误。这对调试可能很
有用:
note $some-object;
通常要用某个命令行开关或其他设置启用这种输出:
note $some-object if $debugging > 0;
输出方法应用于
$*ERR
—其中包含默认的错误文件句柄:
$*ERR.put: 'This is a warning message';
在一个终端中,正常情况下你会同时看到标准输出和标准错误(或者“合并”)。
可以用
2>
重定向错误输出,这会得到文件描述符数字
2
(标准错误),把错误输出
发送到非终端的某个地方。如果还不理解这些内容,可以看看下面的例子:
% perl6 program.p6 2> error_output.txt ...
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