Hi all,

a while ago, I wrote a little subroutine to test wether a given element is in a given 
array:

sub contains {
    
    my $result = 0;
    my $contained = shift;
    foreach (@_) {
        if ($_ eq $contained){ $result = 1; }
    }
    $result;
}

Now I found a nicer solution in "Learning Perl Objects, References & Modules" and 
adapted it:

sub contains {
    my $contained = shift;
    my $result = grep { $contained eq $_ } @_;
}

Smart. But immediately after giving this example, Randal notes that this is not the 
best solution for testing large arrays. Can anyone give me a hint to what he might 
have meant? Or, to put it this way: Randal, what did you think of writing this?

Thanks,

Jan
-- 
The day Microsoft makes something that doesn't suck is the day they start selling 
vacuum cleaners.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to