Is Perl *that* good?

Carl Banks imbosol at aerojockey.invalid
Tue Apr 27 20:09:08 EDT 2004


Roy Smith wrote:
> 
> 
> Carl Banks <imbosol at aerojockey.invalid> wrote:
>> Hmm.  The reason this hasn't been done is that it makes the match
>> method non-reentrant.  For example, suppose you call some functions in
>> between the matching and use of the matched object, like this:
>> 
>>     if myregex.match(line):
>>         xyz = (subprocess(line[myregex.lastm.end():]) 
>>                + myregex.lastm.group(1))
>> 
>> And suppose subprocess goes on to use the same regexp.  By the time
>> subprocess returns, myregex.lastm could have been overwritten.  This
>> is not a far-fetched example at all; one could easily encounter this
>> problem when writing, say, a recursive descent parser.
> 
> I don't see that this is any worse than any other stateful object.

It's worse because, unlike most objects, regexp objects are usually
global (at least they are when I use them).  Moreover, the library
encourages us to make regexp objects global by exposing the regexp
compiler.  So even if you personally use local regexps (and accept the
resulting performance hit), many will declare them global.

In other words, myregexp.match is essentially a global function, so
it shouldn't have state.


-- 
CARL BANKS                      http://www.aerojockey.com/software
"If you believe in yourself, drink your school, stay on drugs, and
don't do milk, you can get work." 
          -- Parody of Mr. T from a Robert Smigel Cartoon



More information about the Python-list mailing list