Getting Elements Out of an Array

So far in this hour, you've been slinging around whole arrays and lists. Many times, though, you need to get to the individual elements of arrays. You need to do so to search arrays, change the values of elements, or to add or remove individual elements from an array.

The simplest way to get the contents of the entire array is to use the array in double quotation marks:

print "@array";

This example prints the elements of @array with a space separating each element.

Individual elements in an array are accessed by an index, as shown in the following code. The index for array elements starts at the number 0 and increases by 1 for each additional element. Each element of the array has an index value, as shown here: ...

Get Sams Teach Yourself Perl in 24 Hours now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.