Re: Speed comparison of regex versus index, lc, and / /i



"A. Sinan Unur" <1usa@xxxxxxxxxxxxxxxxxxx> wrote:
I am not going to change my practice of searching for or checking the
existence of literal strings in text using index because that makes
intuitive sense to me.

I second that. While certainly REs are very powerful and can do many
things sometimes a simpler tool is all you need.

In a way it is similar to using double versus single quotes. If the
programmer used REs (or double quotes) then I expect that there was a
need for them and I start looking for special RE constructs (or items
that interpolate) and when I don't find any then the question becomes
"oops, what did I miss?" It's kind of don't use the big gun unless there
is a need for it.

An extreme example of this overkill could be seen in what I believe may
have triggered Ben's curiosity and his commendable effort to gather some
hard data. Although the OP never comfirmed his actual intentions he
anchored his RE (which he apparently wanted to be a literal match) to
the beginning and end of the string, giving a very strong indication
that in reality he was looking for a trivial 'eq'.

Sure, instead of
$foo eq 'bar'
you can use
$foo =~ m/^\Q$foo\E$/
But why would you want to?

And IMO the same applies to pattern matching when a simpler index() does
the job just as well.

jue
.