[Chicago-talk] Performance issue
Steven Lembark
lembark at wrkhors.com
Thu Apr 21 06:30:11 PDT 2011
On Wed, 20 Apr 2011 22:42:56 -0500
Jay Strauss <me at heyjay.com> wrote:
> I was under the impression that regexs were slow.
In general replacing the contents of a string in-place
will take much less time than using a regex to break
up the string into an array and then paste the array
back together.
For example, stripping the closing quote with a regex
should be quite fast:
while( <> )
{
s{^ \s*? " }{}x; # shortest match to the first quote
s{ " \s* $}{}x; # shortest match to the end of line
s{ [|] }{-}gx; # pipes to dashes
s{ , }{|}gx; # commas to pipes
# use the line here
}
should be about the fastest way you can perform the
replacement.
I'd suggest avoiding a "substr $x, -2" to strip the
trailing quote since any minor change in the file
format (e.g. the source providing ^M^J instead of just
^J for the line endings) will completely break the
process. With the regex you always get everything after
the final quote stripped.
--
Steven Lembark 3646 Flora Pl
Workhorse Computing St Louis, MO 63110
lembark at wrkhors.com +1 888 359 3508
More information about the Chicago-talk
mailing list