Refactor/Rewrite Perl code in Python

Dan Stromberg drsalists at
Sun Jul 24 12:39:16 EDT 2011

On Sun, Jul 24, 2011 at 2:29 AM, Shashwat Anand <anand.shashwat at>wrote:

> I am working with a huge codebase of Perl.
> The code have zero documentation and zero unit-tests.
> It seems like a huge hack.

My condolences.  Er, actually, it sounds kind of fun.

The underlying database schema is horrid.
> So I want to rewrite the whole of it in Python.

Good choice.

> How do I start ?

You're probably going to need to learn a lot about the perl code - it's
probably a good idea to come up with unit, integration and system tests for
it - in perl; document it; and diagram it using something like autodia.

Then after you know what's going on inside and outside the perl, you're
better equipped to rewrite into python.

If you write your automated perl tests in a straightforward way, they can be
mostly straightforwardly translated to python - to get an apples to apples
comparison of how each is functioning.

If you do this module by module, you're less likely to run into problems,
but you're also more likely to preserve some of the original code's

> The idea is to rewrite module by module.
But how to make sure code doesn't break ?

See above.

> How can I import perl and python codes in each other ?

I'm not confident you can, unless perhaps you find that you can use an
alternative VM like Parrot.  However, many languages on Parrot are not
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list