in reply to Efficient regex matching with qr//; Can I do better?

If it's worthwhile to take the regexp compiling outside of the inner while, it's probably worthwhile to take the split out too.

If we knew what you were doing, including having a idea what the patterns are, we might be able to provide a better algorithm.

  • Comment on Re: Efficient regex matching with qr//; Can I do better?

Replies are listed 'Best First'.
Re^2: Efficient regex matching with qr//; Can I do better?
by ysth (Canon) on Jul 11, 2008 at 06:07 UTC
    Since the if block is only entered about 20000 times, changes there aren't likely to make a big difference.

    But yes, seeing what kind of patterns these are would provide some clues. If they are literal strings, for instance, it may be better to not do the qr// but instead do

    if (0 <= index($text, $pattern) && $text =~ /\b$pattern\b/) { }
    (the latter bit just to preserve the \b checks).
      From what I understand, a compiled regexp is just as fast as index for literal strings.