List Data and Variables

If scalar data is defined as being made up of individual things, then you can think of list data as a collective thing—or, more rightly, as a collection of scalar things. Just as the term scalar data can include both numbers and strings, the term list data usually refers to one of two specific things: arrays and hashes.

We'll talk about arrays today and go deeper into hashes tomorrow on Day 5, “Working with Hashes.”

An array is a collection of any number of scalar things. Each individual thing, or element, can be accessed by referring to the number of its position in the array (its index). Array indexes in Perl start from 0. Figure 4.1 shows an illustration of a simple array with some numbers and strings in it.

Figure ...

Get Sams Teach Yourself Perl in 21 Days, Second Edition 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.