James wrote: > > On Feb 10, 2004, at 5:04 AM, Jan Eden wrote: > > > 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 $_ } @_; > > } > > Again, no need for the variable. > > sub contains { > my $contained = shift; > return grep $_ eq $contained, @_; > } > > We can't fix this in the grep() version, because grep() finds ALL > matches, not just the first. It must walk the list to do its job. > However, I snuck in a fix for your version above. Go take a peak...
What do you mean here James? All I can see is that you changed grep BLOCK into grep EXPRESSION reversed the operands of 'eq' and dropped the assignment. Am I missing something? Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>