diff filter.pl @ 2:d7dd496a4fa6 boosterpack

[svn r4] actual functionality!
author robert
date Tue, 08 Sep 2009 02:45:26 -0400
parents
children 8c6d2ce90677
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/filter.pl	Tue Sep 08 02:45:26 2009 -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