Mercurial > boosterpack
annotate filter.pl @ 2:d7dd496a4fa6 boosterpack
[svn r4] actual functionality!
author | robert |
---|---|
date | Tue, 08 Sep 2009 02:45:26 -0400 |
parents | |
children | 8c6d2ce90677 |
rev | line source |
---|---|
robert@2 | 1 sub filter |
robert@2 | 2 { |
robert@2 | 3 |
robert@2 | 4 $ref = shift; |
robert@2 | 5 @list = @_; |
robert@2 | 6 my @ret = (); |
robert@2 | 7 |
robert@2 | 8 for $element(@list) |
robert@2 | 9 { |
robert@2 | 10 if ($ref->($element)) |
robert@2 | 11 { |
robert@2 | 12 push @ret, $element; |
robert@2 | 13 } |
robert@2 | 14 } |
robert@2 | 15 |
robert@2 | 16 return @ret |
robert@2 | 17 |
robert@2 | 18 } |
robert@2 | 19 |
robert@2 | 20 |
robert@2 | 21 |
robert@2 | 22 |
robert@2 | 23 @test = (1,2,3,4,5,6); |
robert@2 | 24 |
robert@2 | 25 sub even |
robert@2 | 26 { |
robert@2 | 27 return ($_[0]%2 == 0); |
robert@2 | 28 } |
robert@2 | 29 |
robert@2 | 30 @rr = &filter(\&even, @test); |
robert@2 | 31 |
robert@2 | 32 print "@rr"; |