From: sln on 15 Jun 2010 17:16 On Tue, 15 Jun 2010 14:07:01 -0700, sln(a)netherlands.com wrote: >On Sun, 13 Jun 2010 07:41:06 -0700 (PDT), Peng Yu <pengyu.ut(a)gmail.com> wrote: > >>If I only have a small number of patterns(say 3), I can just spell out >>the matching code as below. >> >>grep {/$pattern1$/ or /$pattern2$/ or /$pattern3$/} @array; >> >>But if I have @patterns with many patterns that I want grep, the above >>way doesn't work. I'm wondering what is the best way to grep many >>patterns. > >Late to the thread, you have some good potential solutions by now. > >I just want to make a correction to your statement. >If you have @patterns, it is indeed possible to spell it out and it >does work: > >grep {/$pattern[1]$/ or /$pattern[2]$/ or /$pattern[3]$/} @array; > >I don't buy into the propaganda that @patterns are usefull. >Here's why. > >When you split up a real regular expression, those with quantifiers, >groups, and modifiers, the potential for disaster increases exponentially. >Throwing them into "strings" to be dynamically compiled is another problem. >Then there's that dynamic string problem. > >The faq's give the simplest of simple examples and are not real world. >Multi-part regular expressions are fraught with danger in the hands of the novice >(hell, even the experts). > >So, be sure to put this note in the book you are having everybody write for you. >Sorry, no code examples, check the faq. > Oh, btw, grep() sucks. It can't be stopped whence you found what you need. So don't use it for that. Its just a filter (that can't be stopped). Put that in your book. -sln
First
|
Prev
|
Pages: 1 2 3 4 Prev: Negative Lookbehind and Wildcards Next: Where is -e (file test operator) in man? |