Mercurial > boosterpack
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/perl3 sub filter4 {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 @ret20 }25 @test = (1,2,3,4,5,6);27 sub even28 {29 return ($_[0]%2 == 0);30 }32 @rr = &filter(\&even, @test);34 print "@rr";