Logo

Programming-Idioms

History of Idiom 57 > diff from v8 to v9

Edit summary for version 9 by :

Version 8

2015-05-06, 21:04:51

Version 9

2015-07-31, 19:24:56

Idiom #57 Filter list

Create list y containing items from list x satisfying predicate p. Respect original ordering. Don't modify x in-place.

Idiom #57 Filter list

Create list y containing items from list x satisfying predicate p. Respect original ordering. Don't modify x in-place.

Code
# You can use a subroutine as your predicate
@primes_less_than_100 = grep { is_prime($_) } 1 .. 99;

# You can also write your predicate inline
@odd_numbers = grep { $_%2 == 1 } 1 .. 99;