Perl:Filtering an Array

From Progzoo
Jump to navigation Jump to search

A filter applies a test to each element - it removes any element that fails the test.

Using grep

You can use the grep function.

Return only the even numbers in the input list.


[Font] [Default] [Show] [Resize] [History] [Profile]

Manual loop

You can also manually loop through the original list and add desired elements to the resulting list.

Return only the even numbers in the input list.


[Font] [Default] [Show] [Resize] [History] [Profile]