Course of Raku / Advanced / Subroutines / More on MAIN subroutines / Exercises / A command-line flag
Solution: A command-line flag
Here is a possible solution to the task.
Code
sub MAIN(Bool :$shout = False) {
say $shout ?? 'HELLO' !! 'hello';
}🦋 You can find the source code in the file boolean-flag.raku.
Output
$ raku boolean-flag.raku
hello
$ raku boolean-flag.raku --shout
HELLOComments
A
Boolnamed parameter becomes a flag: passing--shoutsets$shouttoTrue, while omitting it leaves the defaultFalse.The ternary then prints
HELLOorhelloaccordingly. Unlike a--name=valueoption, a flag takes no value — its mere presence is what counts.