in reply to Re^2: Matching data against non-consecutive range
in thread Matching data against non-consecutive range

IMO its a good idea to attach "don't do this" notices to a solution like this. Its hopelessly inefficient in comparison to the hash lookup.

---
demerphq

  • Comment on Re^3: Matching data against non-consecutive range

Replies are listed 'Best First'.
Re^4: Matching data against non-consecutive range
by bart (Canon) on Jan 30, 2005 at 11:04 UTC
    Have you benchmarked it? I haven't... it might not be that bad, and it's most likely a lot better than just
    $re = join '|', @list;
    anyway...

    I could try and optimize it a little by making sure it doesn't even attempt to match if it doesn't see a digit:

    /\b(?=\d)$re\b/o

    Ideally, I'd think this would be an excellent problem to solve using a regexp assertion in perl code, thus matching all digits first and then testing if it's within range with a hash, all inside the regexp — if only assertions weren't that hard to implement.

    p.s. grinder has yet another alternative solution to using Regex::PreSuf, it's currently up on his scratchpad, but for some otherwise noble but in this case silly reason of policy (because he frontpaged the thread) he doesn't dare to post it. Please urge him to post it, it'd be a waste to the site if he didn't. He won't listen to me. :)

Re^4: Matching data against non-consecutive range
by Spooner (Acolyte) on Jan 30, 2005 at 09:32 UTC
    It's probably time-efficient enough for most purposes. And the hash lookup is probably memory-efficient enough for most purposes.