Perl-to-Python converter/translator?

Grant Griffin not.this at seebelow.org
Wed Jan 31 16:09:37 EST 2001


In article <959jsd$njn$1 at nnrp1.deja.com>, Lance says...
>
>I'm an experienced Perl programmer who has just been assigned
>a project that must be done in Python.  I'm looking for a
>Perl-to-Python translator to help me out.  I don't expect to
>write the whole project in Perl and translate it, though.  I'm
>just looking for some automation to help me see how my old work
>could be done in Python.
>
>I didn't find anything useful via Google or Vaults of Parnassus
>searches.  So, I would appreciate any pointers!

I haven't seen anything like that anywhere.  I've sometimes wanted something
like that too, but for a different reason--so that I could actually maintain my
old Perl scripts <wink>.

But I _have_ done a little translation _manually_.  Here's how it goes:

1) The translation process is mostly mechanical.  Semantically, Perl and Python
are very similar; most of the difference is just syntax.  (Still, that "little"
difference is why I now use _Python_ instead of Perl!)

2) Much of translating Perl to Python is a "clutter-removal" process.  You will
remove braces, semi-colons, and dollar signs--stuff that you really didn't need
in the first place.  Despite Perl's reputation for brevity, you'll find yourself
with smaller script files, having fewer lines (at least if you don't write
extremely terse Perl--like I never did.)

3) Most of what's left has to do with what we Pythoneers call "Explicit is
better than implicit."  Specifically, you will find yourself adding explicit
variable names to cover what Perl did with all those special "punctuation mark"
things--you know, the things that look like comic-strip cuss words <wink>.  In
particular, you will find yourself writing more code for regular
expressions--even though they are semantically very similar to Perl.  (This is
something I still miss about Perl: compact regular expressions.  Still, given
that explicit is better than implicit, it is a vegatable that one needs to eat.)

To rigorously and correctly translate any-and-all Perl to Python would surely
take a heroic effort, but to do it at about the 90% level can't be all that big
of a job for the language hobbyists out there (anybody know any? <wink>); then,
a Real Live Human Being could fix the remaining 10%.

But in any case, if you are experienced in Perl, you will find Python extremely
easy to pick up.  And after going through Guido's tutorial, I can think of no
better way to learn it than to manually translate some of your old Perl scripts
into Python.

python-is-pretty-much-perl-without-all-the-LSD-ly y'rs,

=g2

_____________________________________________________________________

Grant R. Griffin                                       g2 at dspguru.com
Publisher of dspGuru                           http://www.dspguru.com
Iowegian International Corporation            http://www.iowegian.com




More information about the Python-list mailing list