view 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
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";