Jeff 'Japhy' Pinyan wrote:
>
> >I said I cannot fix the grep() version. I'm just not that cool.
>
> I guess I'm cooler than you. ;)
>
> sub find {
> my $wanted = shift;
> my $found = 0;
> { grep $_ eq $wanted && ++$found && last, @_ }
> return $found;
> }
Ouch! Nobody knows you can do that. Please keep it a secret
or this will become an 'obfuscated Perl' group :)
And these shortcut logical operators annoy me because
they break the 'don't do something for its side-effects'
rule. This is the same as
sub find {
my $wanted = shift;
my $found = ''; # The preferred 'false'
{
grep { $found++, last if $_ eq $wanted } @_;
}
return $found;
}
Anyway, since we're in a subroutine.
sub find {
my $wanted = shift;
grep { return 1 if $_ eq $wanted } @_;
}
which returns zero instead of 'undef', but hey..
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>