view filter.pl @ 10:3b52ac950753 boosterpack tip

going to try to fix this thing
author Robert McIntyre <rlm@mit.edu>
date Mon, 27 Sep 2010 17:24:06 -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";