Course of Raku / Essentials / Positional data types

The @*ARGS array

So far as arrays are 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 beta

The 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
beta

Notice that the program requires no change if you call it as an executable file:

$ ./run.raku alpha beta

The 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

Positional data types / Nested arrays   |   Positional data types / Interpolating arrays


💪 Or jump directly to the exercises to this section.