我在Perl 5.10.1上运行了以下脚本:
#!/usr/bin/perl
use strict;
use warnings;
foreach( my $x =0 ; $x < 1; $x++) { # Line 5
print_line(); # Line 6
}
sub print_line {
print "Function call from line: " . [caller(0)]->[2] . "\n";
}
Run Code Online (Sandbox Code Playgroud)
尽管调用了来自第6行的子例程,但脚本输出了C-style for语句的起始行号:
Function call from line: 5
Run Code Online (Sandbox Code Playgroud)
真正奇怪的是,如果我将一个随机语句放入C-style for循环中的一个空行,caller返回正确的行号:
#!/usr/bin/perl
use strict;
use warnings;
foreach( my $x =0 ; $x < 1; $x++) {
my $x = 3;
print_line(); # Line 7
}
sub print_line {
print "Function call …Run Code Online (Sandbox Code Playgroud) 我在一个抛出异常的类中有这个方法Cannot bind attributes in a Nil type object. Did you forget a '.new'?
method parse() {
grammar FindHeaders {
token TOP { [<not-header> | <header>]+ $ }
token not-header { ^^ <![#]> \N* \n }
token header { ^^ '#'{ 1 .. 6 } <content> \n }
token content { \N+ }
}
class HeaderActions {
method content($match) {
return if $match ~~ m/^^\#\s+<[A..Z]>+e*s/ || $match !~~ m/<[a..z]>/;
return if $match ~~ m/\|/ && ( $match ~~ m:i/project/ || …Run Code Online (Sandbox Code Playgroud) 得到了这门课:
class Mass-lb is Mass {
method new(Rat:D() $value = 1.0) {
self.bless(
:abbr('lb'),
:base_value(453.59237),
:$value,
);
}
}
Run Code Online (Sandbox Code Playgroud)
我创建了这样的别名:
class Mass-lbs is Mass-lb { }
class Mass-pound is Mass-lb { }
class Mass-pounds is Mass-lb { }
class Mass-pnds is Mass-lb { }
Run Code Online (Sandbox Code Playgroud)
但我更喜欢做这样的事情:
my @lb-syn = < lbs pounds pound pnds >;
for @lb-syn {
EVAL 'class ::("Mass-$_") is Mass-lb {}';
}
Run Code Online (Sandbox Code Playgroud)
这会引发错误:
Name ::("Mass-$_") is not compile-time known, and can not serve as a package name
PHP …
我不知道如何获得无缓冲的输入。
我试过:
method get-selection() {
getc();
}
Run Code Online (Sandbox Code Playgroud)
还尝试了 Term::ReadKey 模块:
use Term::ReadKey;
method get-selection() {
read-key();
}
Run Code Online (Sandbox Code Playgroud)
但我仍然必须按 Enter 键才能捕获输入。在文档中找不到任何可能有帮助的内容。
我在 macOS 上。
得到这个代码:
unit module Command::CanRun;
enum OS <win nix>;
sub determine-os {
return 'nix' when $*SPEC.gist.contains('unix', :i);
return 'win' when $*DISTRO.is-win;
}
Run Code Online (Sandbox Code Playgroud)
我想对此进行单元测试:
ok Command::CanRun::determine-os, 'can determine os';
但是,如果不导出子文件,我就无法做到这一点determine-os:
Could not find symbol '&determine-os' in 'Command::CanRun'
尚未找到有关如何对模块中的非导出子程序执行此操作的任何指导。谢谢。
我有一些使用 NativeCall 模块来调用 Windows API 的 Raku 代码:
#! /usr/bin/env raku
use v6;
use NativeCall;
constant BYTE = uint8;
constant WCHAR = uint16;
constant DWORD = int32;
constant REGSAM = int32;
constant WCHARS = CArray[WCHAR];
constant BYTES = CArray[BYTE];
constant HKEY_LOCAL_MACHINE = 0x80000002;
constant KEY_QUERY_VALUE = 0x1 +| 0x0008;
constant ERROR_SUCCESS = 0; # Yeah, I know. The Win-Api uses 0 for success and other values to indicate errors
sub RegOpenKeyExW( DWORD, WCHARS, DWORD, REGSAM, DWORD is rw) is native("Kernel32.dll") …Run Code Online (Sandbox Code Playgroud) 我试图将一个ro属性子类化,使它rw像这样:
has '+content' => (is => 'rw');
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用.这不可能吗?
这段代码$string按照我想要的方式解析:
#! /usr/bin/env raku\n\nmy $string = q:to/END/;\naaa bbb # this has trailing spaces which I want to keep\n\n kjkjsdf\nkjkdsf\nEND\n\ngrammar Markdown {\n token TOP { ^ ([ <blank> | <text> ])+ $ }\n token blank { [ \\h* <.newline> ] }\n token text { <indent> <content> }\n token indent { \\h* }\n token newline { \\n }\n token content { \\N*? <trailing>* <.newline> } \n token trailing { \\h+ }\n}\n\nmy $match = Markdown.parse($string);\n$match.say;\nRun Code Online (Sandbox Code Playgroud)\n输出
\n\xef\xbd\xa2aaa bbb\n\n …Run Code Online (Sandbox Code Playgroud) 好吧,这要么是一个错误,要么我看起来像个十足的白痴,而且我使用的环视断言完全错误。我不关心后者,所以我们开始吧。
我正在测试这个语法:
our grammar HC2 {
token TOP { <line>+ }
token line { [ <header> \n | <not-header> \n ] }
token header { <header-start> <header-content> }
token not-header { \N* }
token header-start { <header-one> }
token header-one { <[#]> <![#]> } # note this negative lookahead here
token header-content { \N* }
}
Run Code Online (Sandbox Code Playgroud)
我想捕获一个只有一个#符号的 Markdown 标题,仅此而已。
这是 Grammar::Tracer/Debugger 的输出:
所以它会直接跳过<header-start>捕获。如果我删除<![#]>否定的前瞻断言,我会得到以下结果:
这是一个错误还是我出去吃午饭了?
作为文本:
TOP
>
| line
>
| | not-header
> …Run Code Online (Sandbox Code Playgroud) 今天尝试安装https://github.com/finanalyst/raku-pod-render时遇到了重大问题。
最大的问题之一是使用 ssl 加密的测试失败。看:
https://github.com/grondilu/libdigest-raku/issues/25
https://github.com/jnthn/p6-io-socket-async-ssl/issues/69
然后是我在三月份提交的这个旧问题: https ://github.com/jnthn/p6-ssh-libssh/issues/18
到目前为止,这是三个不同的模块,我在 Mac 上安装时遇到了麻烦。我的机器上安装了 openssl@1.1 和 openssl@3 brew 软件包。
其他 mac 用户对如何彻底解决这个问题有什么建议吗?