perlquestion
cosmicperl
Hi,<br>
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.<br><br>
<code>
IF ($variable == 1 || $variable == 2 || $variable == 3) {
...
IF ($vaiables == [1,2,3?????????
</code>
<br><br>
Lyle<br><br>
<b>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:-</b>
<code>
sub any {
my $var = shift;
for (@_) { return 1 if $var == $_ }
}
if (any($var,1..2000)) { print "Var is between 1 and 2000 inclusive\n"
+ }
</code>