Re: Expressing AND, OR, and NOT in a Single Pattern
- From: "gf" <greg.ferguson@xxxxxxxxxxxxx>
- Date: 2 Mar 2007 10:27:20 -0800
On Mar 1, 3:18 pm, "h3xx" <amphetamach...@xxxxxxxxx> wrote:
I like doing things in one line:
print grep { /suspended/ && ! /Data_services/ } <DATA>;
I prefer this method too. For clarity and long-term maintenance it is
much better because the esoterica of regex can make the desired
results hard to figure out and the bugs in the pattern even harder to
find.
Also, speed wise, this is a lot faster. The regex engine has to do a
lot of work that can be short circuited by the booleans.
Sometimes it's better to break the search for matching patterns into
single lines too. It's kind of macho programmer-wise to string it all
together into one mondo regex pattern and have it work, but the logic
can get fragile.
The only thing I'd do differently to these patterns is add an anchor
to the 'Data_services' pattern, like so...
/^<Query id='Data_services/
Anchors speed up regex an incredible amount. I did benchmarks of index
vs various ways of using regex, and an anchored qr// that was
initialized outside a loop was the fastest at finding patterns inside
long strings, when the pattern was at the end of the string. At the
beginning of a string it should be equal to index(). Index() was
faster when finding a fixed string somewhere in the middle of another
string.
.
- References:
- Expressing AND, OR, and NOT in a Single Pattern
- From: usaims
- Re: Expressing AND, OR, and NOT in a Single Pattern
- From: Scott Bryce
- Re: Expressing AND, OR, and NOT in a Single Pattern
- From: h3xx
- Expressing AND, OR, and NOT in a Single Pattern
- Prev by Date: Re: Q on regex of LWP::Simple data
- Next by Date: Re: Match a regular expression
- Previous by thread: Re: Expressing AND, OR, and NOT in a Single Pattern
- Next by thread: Re: Expressing AND, OR, and NOT in a Single Pattern
- Index(es):
Relevant Pages
|
Loading