annotate filter.pl @ 8:8c6d2ce90677 boosterpack

[svn r11] saving for transference to cd
author rlm
date Fri, 19 Mar 2010 07:28:10 -0400
parents d7dd496a4fa6
children
rev   line source
rlm@8 1 #!/usr/bin/perl
rlm@8 2
rlm@8 3 sub filter
rlm@8 4 {
rlm@8 5
rlm@8 6 $ref = shift;
rlm@8 7 @list = @_;
rlm@8 8 my @ret = ();
rlm@8 9
rlm@8 10 for $element(@list)
rlm@8 11 {
rlm@8 12 if ($ref->($element))
rlm@8 13 {
rlm@8 14 push @ret, $element;
rlm@8 15 }
rlm@8 16 }
rlm@8 17
rlm@8 18 return @ret
rlm@8 19
rlm@8 20 }
rlm@8 21
rlm@8 22
rlm@8 23
rlm@8 24
rlm@8 25 @test = (1,2,3,4,5,6);
rlm@8 26
rlm@8 27 sub even
rlm@8 28 {
rlm@8 29 return ($_[0]%2 == 0);
rlm@8 30 }
rlm@8 31
rlm@8 32 @rr = &filter(\&even, @test);
rlm@8 33
rlm@8 34 print "@rr";