Mercurial > rlmcintyre
diff BoosterPack/.svn/text-base/filter.pl.svn-base @ 0:0d795f02a8bb tip
initial committ. what was I thinking?
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 27 Sep 2010 16:57:26 -0400 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/BoosterPack/.svn/text-base/filter.pl.svn-base Mon Sep 27 16:57:26 2010 -0400 1.3 @@ -0,0 +1,32 @@ 1.4 +sub filter 1.5 +{ 1.6 + 1.7 + $ref = shift; 1.8 + @list = @_; 1.9 + my @ret = (); 1.10 + 1.11 + for $element(@list) 1.12 + { 1.13 + if ($ref->($element)) 1.14 + { 1.15 + push @ret, $element; 1.16 + } 1.17 + } 1.18 + 1.19 + return @ret 1.20 + 1.21 +} 1.22 + 1.23 + 1.24 + 1.25 + 1.26 +@test = (1,2,3,4,5,6); 1.27 + 1.28 +sub even 1.29 +{ 1.30 + return ($_[0]%2 == 0); 1.31 +} 1.32 + 1.33 +@rr = &filter(\&even, @test); 1.34 + 1.35 +print "@rr"; 1.36 \ No newline at end of file