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
HELLO

Comments

  1. A Bool named parameter becomes a flag: passing --shout sets $shout to True, while omitting it leaves the default False.

  2. The ternary then prints HELLO or hello accordingly. Unlike a --name=value option, a flag takes no value — its mere presence is what counts.

Course navigation

A command-line flag   |   A typed MAIN