r1n0 has asked for the wisdom of the Perl Monks concerning the following question:
Hello monks,
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
-or-
--->110 Main Street, Huntington, AL, 55555
I sincerely appreciate any recommendations.
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
-or-
--->110 Main Street, Huntington, AL, 55555
I sincerely appreciate any recommendations.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: REGEX or Not to REGEX for many items
by Your Mother (Archbishop) on Oct 26, 2009 at 04:33 UTC | |
by r1n0 (Beadle) on Oct 26, 2009 at 12:23 UTC | |
Re: REGEX or Not to REGEX for many items
by sflitman (Hermit) on Oct 26, 2009 at 04:29 UTC | |
Re: REGEX or Not to REGEX for many items
by GrandFather (Saint) on Oct 26, 2009 at 04:16 UTC | |
by r1n0 (Beadle) on Oct 26, 2009 at 12:11 UTC | |
Re: REGEX or Not to REGEX for many items
by Jenda (Abbot) on Oct 26, 2009 at 15:21 UTC | |
Re: REGEX or Not to REGEX for many items
by dmlond (Acolyte) on Oct 26, 2009 at 14:20 UTC | |
Re: REGEX or Not to REGEX for many items
by gregor42 (Parson) on Oct 26, 2009 at 18:48 UTC | |
Re: REGEX or Not to REGEX for many items
by Argel (Prior) on Oct 26, 2009 at 20:21 UTC |
Back to
Seekers of Perl Wisdom