For a sub, which takes no arguments, its definition and the call are very straightforward and easy.
sub call-me { Â Â Â say "I'm called" } call-me;
The syntax for declaring a sub’s parameters is similar to what other languages (including Perl 5.20 and higher) provide.
sub cube($x) { Â Â Â return $x ** 3; } say cube(3); # 27
The required parameters are a comma-separated list in the parentheses immediately after the sub name. No other keywords, such as my, are required to declare them.
sub min($x, $y) { Â Â Â return $x < $y ?? $x !! $y; } say min(-2, 2);Â # -2 say min(42, 24); # 24
(?? … !! is a ternary operator in Perl 6. Also, there’s a built-in operator min; see the details in the Chapter 2.)
The above-declared arguments are required; thus, if a sub is called with a different number of actual arguments, an error will occur.