in reply to Re: how to quickly tell if number is in an array
in thread how to quickly tell if number is in an array

my @array = (1, 2); print "found\n" if grep(3, @array);

which prints found may not be what OP expects


Perl is Huffman encoded by design.

Replies are listed 'Best First'.
Re^3: how to quickly tell if number is in an array
by McDarren (Abbot) on Oct 12, 2005 at 02:23 UTC
    whoops!
    Okay... how about...
    print "found\n" if grep(/^$number\$/, @array);
      So now your using the regex engine.. to test if a number.. is exactly the same as another number?
        yes, this is a bit silly, isn't it.
        I just had a read of the faq on this one, and now I've realised that I need to go back and re-do a few of my utilty scripts...