小编Nor*_*ood的帖子

`MAIN()`参数中的字符串匹配

我想MAIN()用字符串匹配来限制参数.这有效:

sub MAIN(
    Str :$r where * eq any(< aaa bbb ccc >) = "bbb"
) { say $r }

$ perl6 tb.p6 -r="ccc"
ccc
Run Code Online (Sandbox Code Playgroud)

但这不是:

sub MAIN(
   Str :$r where * ~~ m:i/< aaa bbb ccc >/ = "bbb",
) { say $r }

$ perl6 ta.p6 -r="ccc"
Use of uninitialized value of type Any in string context.
Methods .^name, .perl, .gist, or .say can be used to stringify it to something meaningful.
  in whatevercode  at ta.p6 …
Run Code Online (Sandbox Code Playgroud)

perl6

8
推荐指数
1
解决办法
135
查看次数

perl6"首先等待的行动"

该程序创建一个线程来使用dir()读取目录并将文件放在通道上.$ N工作线程读取该通道并"处理"(打印)文件.

但是我得到了这个"等待的操作:"错误.

我已多次阅读有关此错误的陷阱页面,但仍然无法理解它.有人能解释一下这里发生了什么吗?

目录内容:

$ ls
a  b  c  traverse-dir0.p6

运行程序:

$ ./traverse-dir0.p6 
traverse-dir0.p6
a
b
c
An operation first awaited:
  in sub MAIN at ./traverse-dir0.p6 line 24
  in block  at ./traverse-dir0.p6 line 5

Died with the exception:
    Cannot find method 'path': no method cache and no .^find_method
      in block  at ./traverse-dir0.p6 line 16

程序遍历-dir0.p6:

#!/usr/bin/env perl6
# There is a thread to populate $dir-channel by reading filenames in a directory with dir()
# and $N worker threads to …

asynchronous channel perl6

6
推荐指数
1
解决办法
184
查看次数

标签 统计

perl6 ×2

asynchronous ×1

channel ×1