Jump to content

Parse command-line arguments: Difference between revisions

Line 834:
(formerly Perl 6)
At the end of running any top-level code (which can preprocess the arguments if it likes), Raku automatically examines any remaining arguments and transforms them into a call to a <tt>MAIN</tt> routine, if one is defined. The arguments are parsed based on the signature of the routine, so that options are mapped to named arguments.
}</lang perl6>
<lang perl6> sub MAIN (Bool :$b, Str :$s = '', Int :$n = 0, *@rest) {
say "Bool: $b";
say "Str: $s";
say "Num: $n";
say "Rest: @rest[]";
}
}</lang>
</lang>
{{out}}
<pre>$ ./main -h
9

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.