From the course: Perl 5 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

List and array functions

List and array functions - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

List and array functions

- [Voiceover] Perl has a number of useful functions for working with lists and arrays. We've already seen push, pop, shift, and unshift. Here's a few other useful functions. Here I have a working copy of array.pl from chapter 13 of the exercise files, and when I run this, you see we have a list of elements from this array. So let's start with the grep function. The grep function searches and locates elements in a list or array that test true against a given, regular expression. So I can say grep and give it a regular expression and the array, and when I run this, you notice that it's only finding the elements in that array that match that expression. In this case, I was looking for anything with a t in it. I can also give it a negative expression by putting an exclamation point in front of the regular expression. This will search for elements that do not match that, and so here I get the other two. There's also an alternative syntax for grep with instead of just the regular…

Contents