a regular expression question

Alex Martelli aleax at aleax.it
Mon Mar 24 07:34:09 EST 2003


Roy Smith wrote:

> Alex Martelli <aleax at aleax.it> wrote:
>> Oh yes -- I find myself using RE's about 100 times less than I was
>> using them back when I programmed in Perl, thanks on one side to the
>> useful built-in methods of string objects, on the other to higher
>> level library modules and extensions.
> 
> I suspect there's one other reason, and that's because RE's are easier
> to use in Perl than they are in Python.  The toolset drives how you use

Having extensively used both Perl (in the past) and Python (in the last
few years), I strongly disagree.  In particular, one of my relatively
early experiences with Python was a "mass porting" of tons of Perl
scripts that I had authored and accumulated over the years -- I was
sick and tired of maintaining them, and porting everything to the "new
toy" Python seemed a good learning experience as well as a way of
"getting closure" with Perl once and for all so I could then, at
long last, start forgetting it.

I did a somewhat literal transliteration, at first, because my grasp
of Python was not yet perfect AND because my main focus was to make
sure everything worked in the new version so I could cashier the old
one.  Transliterating RE usage, in particular, was never a problem
(as soon as I understood that what i needed was almost invariably
the "search" method rather than the "match" one, that is;-).  One
thing that WAS occasionally problematic was assign-and-test (and
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66061 is how
I worked around THAT one -- you'll see some other "traces" of my
migration in other Cookbook recipes, too;-), btw.


> Perl is a disaster as a general purpose programming language, but the
> one place it shines is the job it was designed for, and that's doing
> pattern matching on text.

It shines at this, yes, but not any brighter than Python does, IMNSHO.


Alex





More information about the Python-list mailing list