如何正确做?
> sub adding(:$first, :$second) { $first + $second }
> adding(second => 2, first => 1)
3
> my %param = second => 2, first => 1
{first => 1, second => 2}
> adding(%param)
Too many positionals passed; expected 0 arguments but got 1
in sub adding at <unknown file> line 1
in block <unit> at <unknown file> line 1
最佳答案
将前缀|
添加到%param
adding( |%param )
这也适用于位置参数
sub foo ( $bar, $baz ){ "$bar:$baz" }
my @args = 'a', 'b';
foo( @args ) # error
foo( |@args ) # "a:b"
关于raku - 在Perl 6中是否可以为命名参数提供一个哈希值?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48244521/