我需要将"cat variousFiles"的结果传递给perl6程序,同时要求程序采用不同的命令行参数.Perl6似乎想把第一个参数作为要读取的文件.我可以重新编写我的例程,但我想使用shell中的管道.有办法吗?
这是我的程序名为testStdInArgs.pl:
say @*ARGS;
for lines() {
say "reading ==> ", $_;
}
Run Code Online (Sandbox Code Playgroud)
我想做(foo和bar是参数):
cat logFile | perl6 testStdInArgs.pl foo bar
Run Code Online (Sandbox Code Playgroud)
以下是错误:
[foo bar]
Earlier failure:
(HANDLED) Unable to open file 'foo'
in block <unit> at stdInArgs.pl line 2
Final error:
Type check failed in binding to $iter; expected Iterator but got Failure (Failure.new(exception...)
in block <unit> at stdInArgs.pl line 2
Run Code Online (Sandbox Code Playgroud)
非常感谢你
是否可以使用联结来匹配联结中的任何值?我想匹配数组中的任何值.这样做的正确方法是什么?
lisprog$ perl6
To exit type 'exit' or '^D'
> my @a=<a b c>
[a b c]
> any(@a)
any(a, b, c)
> my $x=any(@a)
any(a, b, c)
> my $y = "a 1"
a 1
> say $y ~~ m/ $x /
False
> say $y ~~ m/ "$x" /
False
> my $x = any(@a).Str
any("a", "b", "c")
> say $y ~~ m/ $x /
False
> say $y ~~ m/ || $x /
False
> say $y …Run Code Online (Sandbox Code Playgroud) 我正在对大约10000行数进行分析,有些行给出了错误:"在数字上下文中使用Any的未初始化值".我试图捕获此错误,以查看哪些行导致问题.但是,X :: TypeCheck和其他X ::*类似乎没有有效地捕获Nil或Any的自动生成.例如:
try { say Any + 1; CATCH { default { say "oh-no"; } }; }
Run Code Online (Sandbox Code Playgroud)
在打印出警告信息后仍然给我回答"1"并且没有说出我想要的"哦 - 不".
捕获这些非致命自动更新错误的正确方法是什么?顺便说一下,是否有核动力的perl6调试器?
非常感谢你 !!!
lisprog
似乎每次我打电话都spurt没有:append,它会打开并覆盖文件,然后自动关闭文件.我一直在使用spurt在例程中写入数千行代码.现在它似乎浪费了大量的I/O资源.我想如果我需要编写数千行,我应该总是使用"open"来获取文件句柄.评论?
我正在使用Moar.现在可以创建perl6可执行文件吗?
我在machineA上开发了源代码,我想在machineB上运行它,这比machineA快3倍,但我不希望机器B上的人能够查看源代码.
或者我是否必须更改为Java VM?
如果无法创建perl6可执行文件,保护公司/部门知识产权的最佳方法是什么?
非常感谢你 !!!
lisprog
我在.one结点和范围匹配方面遇到了一些问题:
> say (3,5).any ~~ (1 .. 9)
any(True, True)
> say so (3,5).any ~~ (1 .. 9)
True
> say so (3,5).one ~~ (1 .. 9)
False
> say so (3,0).one ~~ (1 .. 9) # expect True because 0 not in range and 3 is
False
> say so (3,0).any ~~ (1 .. 9)
True
> say so (0, 3).one ~~ (1..9) # expected True; 0 not in range; exactly one item (3) is in range
False
> …Run Code Online (Sandbox Code Playgroud) 我正在尝试匹配组中的任何关键字.关键字在数组@b中.我无法进行不区分大小写的匹配.我做了一些测试,下面的脚本就是一个例子:
> my $line = "this is a test line";
this is a test line
> my @b = < tes lin > ;
[tes lin]
> my regex a { || @b };
regex a { || @b }
> say $line ~~ m:i/ <a> / # matching the first as expected
?tes?
a => ?tes?
> say $line ~~ m:i:g/ <a> / # matching both as expected
(?tes?
a => ?tes? ?lin?
a => ?lin?)
> my @b …Run Code Online (Sandbox Code Playgroud) 我需要根据用户提供的功能生成许多数据点。用户通过提示输入功能(“输入功能:”);我正在尝试使用EVAL,但我不断收到错误消息。最好的方法是什么?谢谢 !!!
> my $k = prompt("Enter function: ");
Enter function: sub x($a) { say $a * 2; };
> $k
sub x($a) { say $a * 2; };
> use MONKEY-SEE-NO-EVAL
Nil
> use Test
Nil
> EVAL $k
&x
> say x(4)
===SORRY!=== Error while compiling:
Undeclared routine:
x used at line 1
Run Code Online (Sandbox Code Playgroud)
另外,我在使用Q:f插入函数时也遇到了麻烦。
> Q:f { sub x($a) { say $a * 2; }; }
sub x($a) { say $a * 2; };
> &x
===SORRY!=== Error …Run Code Online (Sandbox Code Playgroud) 快速提问:
-1.9.floor给您-1,而“ -1.9” .floor给您-2。应该是这样吗?对我来说似乎有点矛盾。
> say -1.9.floor
-1
> say "-1.9".floor
-2
Run Code Online (Sandbox Code Playgroud)
文档说“将其向下舍入到最接近的整数”。两者都应该为-2吗?
谢谢!!!
如果列表末尾的数据更重要,并且我希望 :partial list 保留在列表的开头,同时保留初始顺序,我会这样做:
> my @a = (0,1,2,3,4,5,6,7,8,9);
[0 1 2 3 4 5 6 7 8 9]
> say @a.rotor(4, :partial)
((0 1 2 3) (4 5 6 7) (8 9)) # not what I want; important data at end gets cut off;
> say @a.reverse.rotor(4, :partial).reverse.map({$_.reverse});
((0 1) (2 3 4 5) (6 7 8 9)) # this is what I want
Run Code Online (Sandbox Code Playgroud)
有没有办法避免 3 个“反向”操作?是否可以添加 :fromEnd 副词?