Parse command-line arguments: Difference between revisions
Content deleted Content added
Thundergnat (talk | contribs) m syntax highlighting fixup automation |
Thundergnat (talk | contribs) m →{{header|Raku}}: Undo bizarre single space indent that somebody found necessary to do |
||
Line 834: | Line 834: | ||
(formerly Perl 6) |
(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. |
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. |
||
<syntaxhighlight lang="raku" line> |
<syntaxhighlight lang="raku" line>sub MAIN (Bool :$b, Str :$s = '', Int :$n = 0, *@rest) { |
||
sub MAIN (Bool :$b, Str :$s = '', Int :$n = 0, *@rest) { |
|||
say "Bool: $b"; |
say "Bool: $b"; |
||
say "Str: $s"; |
say "Str: $s"; |
||
say "Num: $n"; |
say "Num: $n"; |
||
say "Rest: @rest[]"; |
say "Rest: @rest[]"; |
||
⚫ | |||
} |
|||
⚫ | |||
{{out}} |
{{out}} |
||
<pre>$ ./main -h |
<pre>$ ./main -h |