From the course: Perl 5 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Slices of arrays

Slices of arrays - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

Slices of arrays

- [Voiceover] In Perl, you can easily access ranges and noncontiguous elements of an array. These array subsets are called slices. Here's a working copy of slice.pl from chapter four of the exercise files. And I'll just go ahead and run it so you can see that it lists out with this foreach loop. It lists all of the ten elements of this array. So we have an array, and it's being initialized with a quote word list of ten strings numbered one through ten. If we want to access a particular element of the array, we can use the dollar symbol because the expression returns a scalar. So I can come in here and I can say $array[0] and when I build and run it has the number one down at the end because that's the first element. And you remember that array subscripts start at zero. So if instead here I put in the number five and save and run, you notice that it says six there at the end. If I want more than one element, I use the @ symbol because now it's returning a list. And I can say one, two…

Contents