in reply to testing against an array

How about this:
foreach my $item(@array) { if ($test eq $item) { #do something interesting } }
Hope that helps....

Replies are listed 'Best First'.
Re: Re: testing against an array
by muba (Priest) on Apr 03, 2004 at 20:29 UTC
    Even shorter:

    if (grep { /^$testforthis$/ } @array { #do something }
    See grep for more information.
      Even though the person below me already mentioned this, I felt it needed point out again: You can use any expression with grep, not just a regular expression, so if your testing for equality, use the equality test operator, don't try to coerce a regex in to pretending to be one.

      if( grep $test eq $_, @array )
      A reply falls below the community's threshold of quality. You may see it by logging in.