[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] testing



On 14 Dec 1999, Nicholas G. Thornton wrote:

> in the test part of an if statement is there a way to simplify...
>      if ($value == $a or $value == $b or  $value == $c or $value == $d or ...) 
> ...into...
>      if ($value == ($a or $b or $c or $d or...))
> ...or something similar? I can't seem to find it in the Camel book.
> 
>From a slightly wider perspective than the other posters, who talked about
arrays, hashes and RE's, it strikes me that what you really have is a
switch. If the switch is just a filter and all values are then subject to
the same processing, then existing suggestions seem pertinent.

If the processing depends on the value, then you'd likely want to convert
your test to a Perl "switch" construct - less concise but gets the job
done.

Don't forget that from an execution standpoint that if the individual case
conditionals in the "switch" are simple (like ==) then the construct is
optimized.

I tend to also like the switch because it retains the logic of what you're
doing - testing for one of several discrete values. Some of the other
solutions are compact, likely about as fast, but you look at 'em and
wonder what the prgram logic is 6 months down the road. :-)

Arved



# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org