September 2017
Beginner
402 pages
9h 52m
English
An array in Perl 6 is actually an object of the Array class. Working with classes is a subject of Chapter 8, Object-Oriented Programming. So far, we will discuss how we can access different properties of arrays in Perl 6 programs.
To get the length of an array, call the elems method, as follows:
my @a = 1, 3, 5;say @a.elems; # 3
The three methods—push, pop, and append—modify the array: push adds a new element to the end of the array; pop takes the last element, removes it from the array, and returns it; append adds new elements to the end and, unlike push, can add more than one new element. Let's examine the output of the following program:
my @a = 1, 3, 5;@a.push(7);say @a; # [1 3 5 7]say @a.pop; # 7say @a; # [1 ...
Read now
Unlock full access