September 2017
Beginner
402 pages
9h 52m
English
Perl 6 subroutines also allow optional parameters. These parameters are indicated by the question mark in the signature. To check if the argument was passed, use the built-in defined built-in function, as demonstrated in the following example:
sub greet($name, $greeting?) {
say((defined $greeting) ?? "$greeting, $name!" !! "$name!");
}
greet('John'); # John!
greet('John', 'Good morning'); # Good morning, John!