> >> The suggestion of:
> >>
> >> if($something =~ /^(string0|string1|string2)$/)
> >>
> >> is not equivalent to your original condition. It's also likely to be
> >> inefficient.
> >
> > I get 1 min 15.983sec for "normal" three condition if, and 52.305sse for
> > a regex approach. My
> > test code is:
> >
> > my $type = shift;
> > my $iterate = 1000000;
> >
> > my $item = "lock";
> >
> > if ($type eq "normal") {
> > for (0..$iterate) {
> > print " " if $item =~ /^(?:apple|banana|lock)$/;
> > }
> > }
>
> are you messing with our minds on purpose? Looks like this
> is the regex case
>
> > elsif ($type eq "regex") {
> > for (0..$iterate) {
> > print " " if $item eq "apple" or $item eq "banana" or $item eq
> > "lock";
> > }
> > }
>
> and this is 'normal'
>
> so, was your benchmark right, or switched?
Oops, switched... which means I should reverse the conclusion:
The basic, obvious, more explicit form of the multiple condition is faster - 30%
faster in this
example. Use what works, but a regex isn't going to speed anything up. However, if
most of the
time you have to check against a regex away, you've already spent most of the
difference in
speed... so you may as well combine them.
I shouldn't try writing code when I am mostly asleep - let alone post it to a
mailinglist for
others to see! ;-)
Jonathan Paton
__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]