in reply to Re: Re: Hash/Array of Regular Expressions?
in thread Hash/Array of Regular Expressions?

True, one regex is faster than a hash of regexes... certainly any case that can be accomplished with one shouldn't be squeezed into a data structure. But, I think it is bad to have a hash with closures as values where the closures are repeated and required to be the same... better might be to stick the regexes in an array in that case, and just use $count++ or a regular function instead of anonymous functions. Once you get it distilled that way, to whatever simplicity your problem domain allows, I suspect you'll almost always be able to pick one or the other based on simplicity...

OTOH, a 6 mile regex could be tough to debug... what would be nice would be a module that would let you put in regexes, and tell it to do the matching one way or the other, that way if you've got a lot of them you can switch to the looping mode when you need to find the broken bits.
--
Snazzy tagline here

  • Comment on Re: Re: Re: Hash/Array of Regular Expressions?

Replies are listed 'Best First'.
Re: Re: Re: Re: Hash/Array of Regular Expressions?
by bikeNomad (Priest) on Jun 25, 2001 at 01:50 UTC
    Sorry to mislead you; the callbacks don't have to do the same thing. I just had them that way so I could verify that the code worked and get the count of matching lines. I've changed it to use different callbacks.

    I suspect that a matching module like you describe could be adaptive: it could change its strategy depending on the hit/miss ratio and the number of regexes it had to match.

      I wasn't really meaning the actual text of your example, as it's just an example, I'm just saying that in this case whether you actually need the callbacks to be different is what determines the best data structure to use.
      --
      Snazzy tagline here