|Pathologically Eclectic Rubbish Lister|
REGEX or Not to REGEX for many itemsby r1n0 (Beadle)
|on Oct 26, 2009 at 02:42 UTC||Need Help??|
r1n0 has asked for the
wisdom of the Perl Monks concerning the following question:
I am posting this question in hopes of gaining some knowledge from someone that may have experimented with a solution for this at some point in their past. Also, I hope the responses will help other fellow monks when/if they seek this knowledge. I have over 100,000 files to look at, and each is a text file (.txt). What I want to do is reduce a lot of individual scripts that each perform their own REGEX against each file for a given phrase... into a single script that will do the same thing, but quickly, efficiently, and with something better than a loop through all the items or a huge REGEX with all the items (phrases) crammed one after the other. Ideally, I would like to use a hash of all the phrases being searched. I would like to know if there is a way to use a hash inside of a REGEX and make sure all the punctuation is understood (sorta like doing a quotemeta prior to running the regex). I am open to any method anyone has tested that they know will work. Over time, my list of files are going to grow and so are the phrases I will be searching for. I am guessing the phrases will increase into the thousands over time.
A sample phrase could be something like:
--->The cow jumped over the moon
--->110 Main Street, Huntington, AL, 55555
I sincerely appreciate any recommendations.