例如,在这种情况下:
my @list = (2,) but "bar";
put @list.Str «2?»
Run Code Online (Sandbox Code Playgroud)
似乎没有办法访问“bar”组件。我错过了什么吗?同样会发生,例如,Set
my @list = (2,3) but Set(4,5);
put @list.Set; # OUTPUT: «3 2?»
Run Code Online (Sandbox Code Playgroud) 当我从源安装rakudo时:
$ git clone git@github.com:rakudo/rakudo.git
$ cd rakudo
$ perl Configure.pl --gen-moar --gen-nqp --backends=moar
$ make
$ make install
Run Code Online (Sandbox Code Playgroud)
它生成以下文件./install/bin:
$ ls -1 install/bin
moar
nqp
nqp-m
perl6
perl6-debug
perl6-debug-m
perl6-gdb-m
perl6-lldb-m
perl6-m
perl6-valgrind-m
raku
raku-debug
rakudo
rakudo-debug
rakudo-debug-m
rakudo-gdb-m
rakudo-lldb-m
rakudo-m
rakudo-valgrind-m
Run Code Online (Sandbox Code Playgroud)
我知道raku,rakudo和perl6是用于运行一个命令.raku脚本,但什么是其他命令,我如何使用它们?
再次在这个问题的尾部,我试图will用这个(打高尔夫球的)代码使特征起作用:
sub show-value( $a-var ) {
say "Value of {$a-var.^name} is ", $a-var.gist;
}
sub do-stuff () {
ENTER { say "Going in"; }
our $bar will enter { show-value($_) };
$bar = "baz";
LEAVE { say "Leaving"; }
}
do-stuff();
Run Code Online (Sandbox Code Playgroud)
这只是打印“进入”。如果您在全局范围内执行此操作,则它(不会)以相同的方式工作。请注意,这几乎是文档示例的直接实现。
我找到了这个从多个文件中连接相同行的衬垫。如何在两行之间添加空格?
如果文件 A 中的第 1 行是蓝色,而文件 B 中的第 1 行是天空,则获得 bluesky,但需要蓝色天空。
say $_ for [Z~] @*ARGS.map: *.IO.lines;
我在 Windows 上的 64 位 dll 中有此代码
#define TEMPLATENEST_API __declspec(dllexport)
extern "C" TEMPLATENEST_API void templatenest_init(void** object);
void templatenest_init(void** object)
{
//TemmplNest
*object =(void*) new TemplateNestClass();
}
Run Code Online (Sandbox Code Playgroud)
在乐中,
sub templatenest_init(Pointer is rw) is native(dl) { * }
my Pointer $class_pointer;
templatenest_init($class_pointer);
templatenest_init($class_pointer)
Run Code Online (Sandbox Code Playgroud)
然而,在这一行之后,$class_pointer 为 0。不知何故,类指针的值没有到达 Raku。我在调试器中检查了 *object 被设置为非零值。
导出函数的签名
2 1 00025621 templatenest_init = @ILT+5660(templatenest_init)
最小示例:使用 Microsoft VIsual studio 2019 编译为 dll 库 64 位
乐:
use v6;
use Data::Dump;
use NativeCall;
#constant dl = 'D:\m\cpp\TemplateNest\template-nest-rakudl\TemplateNestDll.dll';
constant dl = 'D:\m\cpp\TemplateNest\x64\Debug\DllMinitest.dll';
sub …Run Code Online (Sandbox Code Playgroud) 收到:
use Lingua::En::Titlecase:from<Perl5>;
# this line is straight from doc
my $tc = Lingua::EN::Titlecase.new("CAN YOU FIX A TITLE?");
Run Code Online (Sandbox Code Playgroud)
得到这个:
Could not find symbol ''&Titlecase'' in ''GLOBAL::Lingua::EN''
Run Code Online (Sandbox Code Playgroud)
我记得Inline::Perl5大约一个月前,当我踢轮胎时,它为我工作。不确定我做错了什么。文档没有为我提供任何线索
得到这样的文字:
Want this || Not this
该行也可能如下所示:
Want this | Not this
用一根管子。
我使用这个语法来解析它:
grammar HC {
token TOP { <pre> <divider> <post> }
token pre { \N*? <?before <divider>> }
token divider { <[|]> ** 1..2 }
token post { \N* }
}
Run Code Online (Sandbox Code Playgroud)
有一个更好的方法吗?我很乐意能够做更多这样的事情:
grammar HC {
token TOP { <pre> <divider> <post> }
token pre { \N*? }
token divider { <[|]> ** 1..2 }
token post { \N* }
}
Run Code Online (Sandbox Code Playgroud)
但这是行不通的。如果我这样做:
grammar HC {
token TOP { …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并在其中添加一些逻辑,但有一个更简单的方法,对吗?
收到:
my @list = <one two three>;
my %hash;
my $item1 = @list.shift;
%hash{$item1} = {$item1 => 1};
my $item2 = @list.shift;
%hash{$item1} = {$item2 => 1};
my $item3 = @list.shift;
%hash{$item1}{$item2} = {$item3 => 1};
say %hash;
Run Code Online (Sandbox Code Playgroud)
输出所需的数据结构:
{one => {two => {three => 1}}}
Run Code Online (Sandbox Code Playgroud)
显然,如果是递归的话会更好,所以我这样写:
sub get-hash(%parent-hash, $last-item, *@list) {
my $item = @list.shift;
%parent-hash{$last-item} = { $item => 1 };
get-hash(%parent-hash{$last-item}, $item, @list) if @list;
return %parent-hash<root>;
}
%hash = get-hash({}, 'root', @list2);
Run Code Online (Sandbox Code Playgroud)
输出:
{one => {two …Run Code Online (Sandbox Code Playgroud) 为什么第一个表达式可以解释而第二个表达式不能解释?
\n我理解它们是相同的,即调用匿名正则表达式的字符串。
("foo").first: /foo/ andthen say "$_ bar";\n> foo bar\nRun Code Online (Sandbox Code Playgroud)\n"foo": /foo/ andthen say "$_ bar";\n> Confused\n> at /home/dmc7z/raku/foo.raku:2\n> ------> "foo":\xe2\x8f\x8f /foo/ andthen say "$_ bar";\n> expecting any of:\n> colon pair\nRun Code Online (Sandbox Code Playgroud)\n