Other Ways to Mess with Lists

But wait, that's not all. I've got a couple more functions that are useful for modifying and playing with lists: reverse, join, and map.

reverse

The reverse function takes each element of a list and turns it blue. Just kidding. reverse, as you might expect, reverses the order of the elements in the list:

@otherway = reverse @list;

Note that if you're sorting a list, or moving elements around using shift, unshift, push, or pop, you can use those methods to create reversed lists without having to reverse them using reverse (try to avoid moving array elements around more than you have to).

The reverse function also works with scalars, in which case it reverses the order of characters in a scalar. We'll come back to ...

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.