in reply to better way to find list members?

Update: Aside from changing foreach to for and using $_ in the loop, it seems i did use the for loop. having made those changes and being resistent to using a hash for a simple list of numbers, is there anything else I'm missing? -- aside from massive amount of skills and the sheer power of having memorized the docs ; )

OK, should always go with my instincts when i feel I shouldn't post. : )

Two things I should have mentioned are that 1. I really wanted this to be tucked away in a sub which returns true or false and could be passed any number of dif. args, as in the example and 2. The arrays are coming from simple lists of numbers, just like the example array - so a hash seemed to be overkill.

many good suggestions in these replies - be benchmarking for now.

-- I'm a solipsist, and so is everyone else. (think about it)

Replies are listed 'Best First'.
RE: (more specific) Re: better way to find list members?
by cwest (Friar) on Oct 17, 2000 at 00:49 UTC
    If you insist on just wrapping grep in a subroutine...
    my $array = [ 1 .. 50 ]; sub mygrep { my( $guess, $array ) = @_; grep { $_ == $guess } @{$array}; } print mygrep( 165, $array ) ? "True\n" : "False\n";
    Enjoy!
    --
    Casey
       I am a superhero.