Variadic function
If a subroutine has no formal parameters but mentions the variables @_
or %_
in its body, it will accept arbitrary positional or keyword arguments, respectively. You can even use both in the same function.
This prints:
Raku also supports slurpy arrays and hashes, which are formal parameters that consume extra positional and keyword arguments like @_
and %_
. You can make a parameter slurpy with the *
twigil. This implementation of &foo
works just like the last:
Unlike in Perl 5, arrays and hashes aren't flattened automatically. Use the |
operator to flatten:
Last updated