I figured I should try the benchmark against ur original question.

use Benchmark qw(cmpthese);
$now = time;
my $t = "bob";
my $count = 5000000;
cmpthese ($count, {
        'OR' => sub {
            1 if ($t eq "joe" or $t eq "bar" or $t eq "foo" or $t eq "bob" );
        },
        'RE' => sub {
            1 if ($t =~ /^(joe|bar|foo|bob)$/);
        },
        }
);
print "\n", time - $now, " seconds\n";

        Rate   RE   OR
RE  384025/s   -- -72%
OR 1377410/s 259%   --

37 seconds

But changing it to single letters (if $t eq "a" or... vs. m/[a-e]/), the
regex wins.

        Rate   OR   RE
OR 1138952/s   -- -38%
RE 1824818/s  60%   --

27 seconds




At 08:09 PM 3/2/05 -0500, Paul Rogers wrote:
>What's the simplest/shortest way to write an IF statement given that I'm 
>looking for the variable to be one of 5 possible choices?
>
>E.g.,
>
>if ($x eq 'a' or $x eq 'b' or $x eq 'c or $x eq 'd' or $x eq 'e') {
>    blah
>}






--
REMEMBER THE WORLD TRADE CENTER         ---=< WTC 911 >=--
"...ne cede males"

00000100

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to