Lists and Arrays

Perl has a number of features that make it easy to manipulate an entire list or array.

map and grep

In Chapter 16, we mentioned the map and grep list-processing operators. They can do more than we could include here. See the perlfunc manpage for more information and examples, and check out the Alpaca for more ways to use map and grep.

The splice Operator

With the splice operator, you can add items to the middle of an array or remove them, letting the array grow or shrink as needed. (Roughly, this is like what substr lets you do with strings.) This effectively eliminates the need for linked lists in Perl. See the perlfunc manpage.

Get Learning Perl, Fourth 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.