How about this?

if($something =~ /^(string0|string1|string2)$/){

-----Original Message-----
From: Shaun Fryer [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 23, 2002 1:15 PM
To: Perl Beginners
Subject: evaluating multiple conditions


Is there a simple way to evaluate multiple conditions in an if or
unless statement? For example take the following very simple example.

if (($something eq 'string0') || ($something eq 'string1') || ($something =~
/string2/)) {
  &do_something;
} else {
  &do_somthing_else;
}

Being a bit of a spartan I think it would be nice if I could do it
like the following instead.

if ($something eq ('string0' || 'string1' || =~ /string2/)) {
  &do_something;
} else {
  &do_somthing_else;
}

But the latter doesn't seem to work. So, as a kluge I've been doing as
follows.

my $test_ok;
$test_ok = 1 if ($something eq 'string0');
$test_ok = 1 if ($something eq 'string1');
$test_ok = 1 if ($something =~ /string2/);
if ($test_ok) {
  &do_something;
} else {
  &do_somthing_else;
}

Is there a better way to simplify the syntax when testing for multiple
conditions?

===================
 Shaun Fryer
===================
 London Webmasters
 http://LWEB.NET
 PH:  519-858-9660
 FX:  519-858-9024
===================


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to