Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: REBOL embedded $variables regexp/no

From: joel:neely:fedex at: 11-Dec-2002 13:25

Hi, Tom, <ROTFL>Thanks, I needed that after a looooong meeting this AM!</ROTFL> Tom Conlin wrote:
> > > > $bigstring =~ s/\s+/ /g; > >
...
> > > > Within the variable named "bigstring" replace all runs of > > whitespace (*) with a single blank. > > > > (*) technically it says "one or more consecutive whitespace > > characters", which I feel justified in verbalizing as > > "runs of whitespace". > > > > that flaw could creep thru is very telling. > > Q: does the regrxp do what it is intended to? > > A: only if you also wanted to replace every_single space with a > single_space as well. >
You're EXACTLY right (but it wasn't a "flaw"; see below).
> an expression that may come closer to your intent is > > $bigstring =~ s/ \s+/ /g; >
For what it's worth, I considered (and deliberately rejected) using that version in my email. I decided to use the simplest pattern that would work, rather than the most efficient for run time, because I didn't want to obscure the main point (the convenience of having some simple pattern-match-and-replace capabilities) with a discussion of how to optimize regular expressions. Having to explain the additional blank character would have added to the length of my email, which was becoming dangerously long anyway. Put another way, I optimized for reader time instead of code speed. Preliminary benchmarking showed that 87.2% of the readers completed the email with the shorter RE an average of 12.9% faster, and only 0.0001% percent of the readers picked up on the subtle distinction that you noticed (making you a "one in a million" kind of guy! ;-) Incidentally, 46.8% of all statistics are made up on the fly! -jn- -- ---------------------------------------------------------------------- Joel Neely joelDOTneelyATfedexDOTcom 901-263-4446