http://qs1969.pair.com?node_id=516797

cosmicperl has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
  I was writting a long list of OR's (||) in several IF statements, then it occured to me. I'm sure there is way of listing all the or values rather than repeating the same variable and each individual value. After searching on the net, I haven't come up with anything, so I've come for some sage wisdom from the best place possible.

IF ($variable == 1 || $variable == 2 || $variable == 3) { ... IF ($vaiables == [1,2,3?????????


Lyle

Update: Great to see so many responses and expecially great to see that Perl6 will have an a'any' function to deal with this nicely. In my opinion for overall speed and efficiency bageler's solution is best:-
sub any { my $var = shift; for (@_) { return 1 if $var == $_ } } if (any($var,1..2000)) { print "Var is between 1 and 2000 inclusive\n" + }