Course of Raku / Essentials / More about types / Positional data types
The @*ARGS array
Now that arrays have been introduced, it is a good time to meet one
of the built-in arrays, @*ARGS. The * in its
name is the second sigil, or twigil, and we’ll see more of them
in the future. But for now, let’s get the advantages of using that
special array. It contains the arguments that the program gets from the
command line.
Consider the following program run:
$ raku run.raku alpha betaThe program run.raku gets two parameters:
alpha and beta. They can be read from
@*ARGS.
say @*ARGS.elems;
say @*ARGS[0];
say @*ARGS[1];This program prints the number of arguments passed to it and the arguments themselves:
$ raku run.raku alpha beta
2
alpha
betaNotice that the program requires no change if you call it as an executable file:
$ ./run.raku alpha betaThe program, in this case, should have a
shebang, but the most important thing is that the indices of
@*ARGS still start with 0:
#!/usr/bin/env raku
say @*ARGS.elems;
say @*ARGS[0];
say @*ARGS[1];Practice
Complete the quiz that covers the contents of this topic.
Course navigation
← Quiz — Nested
arrays | Quiz
— The @*ARGS array →
💪 Or jump directly to the exercises in this
section.
Translations of this page: English • Deutsch • Español • Italiano • Latviešu • Nederlands • Български • Русский • Українська