Course of Raku / Essentials / The MAIN
function / Multiple MAIN
functions
Quiz — Multi-MAIN
There are three versions of the MAIN
function in this program:
multi sub MAIN() { say 'Default mode' }
multi sub MAIN('help') { say 'Help mode' }
multi sub MAIN(Str $mode) { say "Mode '$mode'" }
What does the program print if it is run by one of the following commands:
1
$ raku t.raku new
Prints “Mode 'new'” | (: Prints “Default mode”, Prints “Help mode”, Prints “Mode 'new'”, Terminates with an exception :) |
2
$ raku t.raku 1001
Prints “Mode '1001'” | (: Prints “Default mode”, Prints “Help mode”, Prints “Mode '1001'”, Terminates with an exception :) |
3
$ raku t.raku
Prints “Default mode” | (: Prints “Default mode”, Prints “Help mode”, Prints “Mode ''”, Terminates with an exception :) |
4
$ raku t.raku Help
Prints “Mode 'Help'” | (: Prints “Default mode”, Prints “Help mode”, Prints “Mode 'Help'”, Terminates with an exception :) | Parameters are case sensitive in this case. |
Course navigation
←
The MAIN
function / Reading command-line arguments
|
The MAIN
function / Using unit sub
→
💪 Or jump directly to the exercises to this section.
Translations of this page: English • Deutsch • Español • Italiano • Latviešu • Nederlands • Български • Русский • Українська