Is Perl *that* good?

Skip Montanaro skip at pobox.com
Tue Apr 27 13:33:10 EDT 2004


    Roy> For the occasional ad-hoc match, this is fine.  The advantage of
    Roy> pre-compiling is that it's faster, since it doesn't have to
    Roy> recompile the regex each time.

    Roy> I don't see anything in the reference manual which says re.match() 
    Roy> caches compilations, but I suspect it does.

Yup, every call does.  I believe the only time you really need to compile
them is if you have more than 100 different regular expressions.  In this
case the caching code clears the cache when the threshold is reached instead
of just picking a random few elements to toss (which seems like a mistake to
me but one that should rarely be encountered).  Look in sre.py at _compile()
and _MAXCACHE.

Skip




More information about the Python-list mailing list