in reply to IF Statement Testing

If you're looking to exclude specific values (not necessarily contiguous), then here is another way to solve your problem:

if (scalar grep { $expire ne $_ } @values) { die "Don't tamper with m +e!"; }

Where @values is filled with the values you want to check for.  Also, if you are doing only numbers you can change the ne test to a != test.

Update:  Added italics to "another" to emphasize TMTOWTDI.  For further insight into TMTOWTDI (and why algorithms, unlike men, are not all created equal), might I suggest reading the chain of replies resulting from this post.

Replies are listed 'Best First'.
Re^2: IF Statement Testing
by davido (Cardinal) on May 14, 2005 at 15:41 UTC

    Yes, you can use grep, but that means doing a linear search that only exits after stepping through all elements, even if the first element found satisfies the criteria. If this conditional is to be tested repeatedly, doing a hashtable lookup is more elegant and more efficient...and depending on who you ask, easier on the eyes.


    Dave

      Yes, I agree using a hash is the best implementation.  Dark, wierd, and frought with perils would be the situation where grep would be the best choice.  TMTOWTDI doesn't mean all algorithms are equal... :)