第一的:
$ raku -e "for 1...6, 7...15 { .say }"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Run Code Online (Sandbox Code Playgroud)
现在:
$ raku -e "for 1...3, 7...15 { .say }"
1
2
3
7
11
15
Run Code Online (Sandbox Code Playgroud)
我希望这个案例打印 1,2,3,7,8,... 15。
这里发生了什么事?
raku 在尝试useLibXML::Reader 时冻结。
use v6;\n\nuse LibXML::Reader;\n\nsub dump-node($reader)\n{\n printf "%d %d %s %d\\n",\n $reader.depth,\n $reader.nodeType,\n $reader.name,\n $reader.isEmptyElement;\n}\n\nmy LibXML::Reader $reader .= new(file => "filtered.xml")\n or die "cannot read filtered.xml";\n\nwhile $reader.read\n{\n dump-node($reader);\n} \nRun Code Online (Sandbox Code Playgroud)\n在 Windows 11 中。
\n$ raku --version\nWelcome to Rakudo\xc3\x94\xc3\xa4\xc3\xb3 v2022.07.\nImplementing the Raku\xe2\x94\xac\xc2\xab Programming Language v6.d.\nBuilt on MoarVM version 2022.07.\nRun Code Online (Sandbox Code Playgroud)\n有趣的字符串“Rakudo\xc3\x94\xc3\xa4\xc3\xb3”才是终端中真正显示的内容。
\n将代码页更改为 UTF-8 修复了有趣的字符。
\n$ chcp 65001\nActive code page: 65001\n\n$ raku --version\nWelcome to Rakudo\xe2\x84\xa2 v2022.07.\nImplementing the Raku\xc2\xae Programming Language v6.d.\nBuilt on MoarVM version …Run Code Online (Sandbox Code Playgroud) 用"cro sub"创建了一个websocket服务器.
写了这个客户:
use v6;
use Cro::WebSocket::Client;
constant WS-PORT = '20000';
constant WS-ADDRESS = 'localhost';
constant WS-PATH = 'chat';
constant WS-URL = 'ws://' ~ WS-ADDRESS ~ ':' ~ WS-PORT ~ '/' ~ WS-PATH;
constant TIMEOUT-TO-CONNECT = 5; # seconds
my $timeout;
my $connection-attempt;
await Promise.anyof(
$connection-attempt = Cro::WebSocket::Client.connect(WS-URL),
$timeout = Promise.in(TIMEOUT-TO-CONNECT));
if $timeout.status == Kept
{
say "* could not connect to server in ', TIMEOUT-TO-CONNECT, ' seconds";
exit 1;
}
if $connection-attempt.status != Kept
{
say "* error ", …Run Code Online (Sandbox Code Playgroud) 所以,我有这个:
my $conn = await IO::Socket::Async.connect('127.0.0.1', 12340);
$conn.print: "GET /rest HTTP/1.1\r\n\r\n";
Run Code Online (Sandbox Code Playgroud)
如何只接收来自服务器的第一行?
我可以使用whenever并在其中添加一些逻辑,但有一个更简单的方法,对吗?