in reply to Style question: regex versus string builtin function

I'd definitely go for the regex. If I later would read that code, I'd have to think for half a second about the index code to see that's it's not a "where is this needle", but that it's a "does the needle exist anywhere", while a regex immediately gives that kind of association. If index is faster, that is an implementation detail. If we care, we should just fix the perl optimization code to make them equivalent. But by default clarity not speed is the goal of writing code.
  • Comment on Re: Style question: regex versus string builtin function

Replies are listed 'Best First'.
Re^2: Style question: regex versus string builtin function
by rir (Vicar) on Oct 02, 2007 at 15:02 UTC
    that it's a "does the needle exist anywhere", while a regex immediately gives that kind of association

    g, that doesn't work for me.

    Regexes are inherently more complex to use than the index function. There are the various regular expression dialects, there are the modifiers, and there are the global variables upon which they may trample.

    But, like others, I tend to reach for the match operator.

    Be well,
    rir