September 2017
Beginner
402 pages
9h 52m
English
Array variables can host more than one value. The values can be of the same type, or can be of different types. Arrays are often used to keep lists of data items.
Arrays in Perl 6 are prefixed with the @ sigil. To access the elements of an array, the postfix pair of square brackets is used. For example, the second element of the @a array is @a[1]. Note that indexing starts from zero.
Let's take a look at how to create an array of integer numbers:
my @odd_numbers = 1, 3, 5, 7, 9, 11;
Alternatively, you can use parentheses or angle brackets. The following two arrays are the same as the previous one:
my @array2 = (1, 3, 5, 7, 9, 11);my @array3 = <1 3 5 7 9 11>;
When printing it using the say built-in function, Perl 6 prints the content ...