Command-line arguments: Difference between revisions

Content added Content deleted
m ({{omit from|GUISS}})
m (→‎{{header|Perl 6}}: spurious newlines)
Line 778: Line 778:
Perl 5's <code>@ARGV</code> is available as <code>@*ARGS</code>. Alternatively, if you define a subroutine named <code>MAIN</code>, Perl will automatically process <code>@*ARGS</code> according to Unix conventions and <code>MAIN</code>'s signature (or signatures, if your <code>MAIN</code> is a multi sub) and then call <code>MAIN</code> with appropriate arguments; see [http://perlcabal.org/syn/S06.html#Declaring_a_MAIN_subroutine Synopsis 6] or [http://perlgeek.de/en/article/5-to-6#post_14|5-to-6].
Perl 5's <code>@ARGV</code> is available as <code>@*ARGS</code>. Alternatively, if you define a subroutine named <code>MAIN</code>, Perl will automatically process <code>@*ARGS</code> according to Unix conventions and <code>MAIN</code>'s signature (or signatures, if your <code>MAIN</code> is a multi sub) and then call <code>MAIN</code> with appropriate arguments; see [http://perlcabal.org/syn/S06.html#Declaring_a_MAIN_subroutine Synopsis 6] or [http://perlgeek.de/en/article/5-to-6#post_14|5-to-6].


<lang perl6># with arguments supplied
<lang>
# with arguments supplied
$ perl6 -e 'sub MAIN($x, $y) { say $x + $y }' 3 5
$ perl6 -e 'sub MAIN($x, $y) { say $x + $y }' 3 5
8
8
Line 786: Line 785:
$ perl6 -e 'sub MAIN($x, $y) { say $x + $y }' 3
$ perl6 -e 'sub MAIN($x, $y) { say $x + $y }' 3
Usage:
Usage:
-e '...' x y
-e '...' x y</lang>
</lang>


If the program is stored in a file, the file name is printed instead of <code>-e '...'</code>.
If the program is stored in a file, the file name is printed instead of <code>-e '...'</code>.