sub count-a {
my $word = "banana";
my $count = 0;
my $foo; # Source of error: $foo intentionally not given a value.
# The value ought to be zero.
while True {
$foo = index $word, "a", $foo;
last unless $foo.defined;
$foo++;
$count++
}
return $count;
}
say count-a;
这个错误信息是错误的吗?
Cannot resolve caller index(Str: Str, Any); none of these signatures match:
(Str:D $: Cool:D $needle, *%_)
(Str:D $: Str:D $needle, *%_)
(Str:D $: Cool:D $needle, Cool:D $pos, *%_)
(Str:D $: Str:D $needle, Int:D $pos, *%_)
in sub count-a at scrap.p6 line 11
in block <unit> at scrap.p6 line 18
错误消息说 index() 将接受“Any”的第三个参数,这是我用 $foo.WHAT 验证时给出的。