Perl 6 Perl 6 today #40

Subroutines, optional params

To indicate a parameter is optional, suffix it with ?

sub speak($phrase, $how_loud?) { ... }

Or, give it a default value:

sub greet($name, $greeting = "Hello") {
    say "$greeting, $name";
}

greet('Robert');               # Hello, Robert
greet('Patrick', 'Bonjour');   # Bonjour, Patrick
Copyright © 2009
http://www.pmichaud.com/2009/pres/