in reply to how to quickly tell if number is in an array

print "found\n" if grep($number, @array);

Replies are listed 'Best First'.
Re^2: how to quickly tell if number is in an array
by GrandFather (Saint) on Oct 12, 2005 at 01:30 UTC
    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.
      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?