O'Reilly logo

Sams Teach Yourself Perl in 21 Days, Second Edition by Rafe Colburn, Laura Lemay

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Modifying List Elements

You can always add and remove list, array, and hash elements using the methods I described on Days 4and 5. But sometimes the standard ways of adding and removing elements from lists can be awkward, hard to read, or inefficient. To help with modifying lists, Perl provides a number of built-in functions, including

  • push and pop: add and remove list elements from the end of a list.

  • shift and unshift: add and remove list elements from the start of a list.

  • splice: add or remove elements anywhere in a list.

push and pop

The push and pop functions allow you to add or remove elements from the end of a list, that is, it affects the highest index positions of that list. Both push and pop will be familiar functions if you've ever worked ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required