How to do it correctly?
> 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
Add a prefix |
to %param
adding( |%param )
This also works for positional arguments
sub foo ( $bar, $baz ){ "$bar:$baz" }
my @args = 'a', 'b';
foo( @args ) # error
foo( |@args ) # "a:b"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With