Is Perl *that* good?

Roy Smith roy at panix.com
Tue Apr 27 15:01:11 EDT 2004


In article <pan.2004.04.27.18.15.56.169064 at hotmail.com>,
 Paramjit Oberoi <p_s_oberoi at hotmail.com> wrote:

> >     Asun> Regex is much more 'immediate' in Perl.  
> > 
> > Sure, it's syntactically bound into the language.  There will always be an
> > extra constant overhead to enable regular expressions in Python.  That
> 
> If only compiled regular expression objects allowed easy access to the
> last match object, python regxes would become significantly more
> convenient.  For example, today you have to write:
> 
> m = myregex.match(line)
> if (m):
>     xyz = m.group('xyz')
> 
> It would be much easier to do:
> 
> if myregex.match(line):
>     xyz = myregex.lastm.group('xyz')
> 
> Having to introduce a new variable name for a match object just
> muddles the code unnecessarily in common regex usage scenarios.
> 
> -param

I like that idea.  I would go one step further and eliminate the lastm 
attribute, so you could just do:

if myregex.match(line):
    xyz = myregex.group('xyz')

Maybe even go all the way and let a regex object have all the methods of 
a match object, cache a reference to the last match, and delegate calls 
to the match object methods to the cached match object.



More information about the Python-list mailing list