view filter.pl @ 9:9652dc713ba6 boosterpack

working on adding to rlmcintyre.com
author Robert McIntyre <rlm@mit.edu>
date Sat, 26 Jun 2010 20:06:08 -0400
parents 8c6d2ce90677
children
line wrap: on
line source
1 #!/usr/bin/perl
3 sub filter
4 {
6 $ref = shift;
7 @list = @_;
8 my @ret = ();
10 for $element(@list)
11 {
12 if ($ref->($element))
13 {
14 push @ret, $element;
15 }
16 }
18 return @ret
20 }
25 @test = (1,2,3,4,5,6);
27 sub even
28 {
29 return ($_[0]%2 == 0);
30 }
32 @rr = &filter(\&even, @test);
34 print "@rr";