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

Re: [MacPerl] testing



At 3:54 PM -0800 12/14/99, 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.

Do you really mean exact arithmetical equivalence (==)?

If you can use pattern matching, there's alternation:

#!perl -wl

$x = "Eureka!"; $a = 'this'; $b = 'that'; $c = 'theother'; $d = 'huh?';
print "What value? ";
$value = <STDIN>;
$value =~ /($a|$b|$c|$d)/i or $x = "Boo!";
print $x;

__END__
- Bruce

_Bruce_Van_Allen___bva@cruzio.com__831_429_1688_V_
_PO_Box_839__Santa_Cruz_CA__95061__831_426_2474_W_

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