Foreword

Theoretically
it's possible to convert every Perl programm into an equivalent programm written in Python since both languages are turing-complete (at least they should ;-)
Practically
this is nearly impossible since Perl and Python have a very differt style of expressing things.

What 'bridgekeeper' does

'bridgekeeper' helps converting Perl code to Python source. The quality of the output Python source depents on the quality of the input code.

If there are constructs within the Perl code which are not possible in Python, you will get warnings. Eg. when using a name for both a hash and a scalar within the same scope (%foo, $foo).

'bridgekeeper' consists of

  • a Perl compiler back-end emitting Python-like source and
  • a runtime Python package which tries to emulate some perl build-in functions.

The name was inspired be the bridgekeeper-scene in Monty Pythons 'Search for the Holy Grail'.

Features

  • Already converts a lot of Perl code-constructs into Python source: loops, special variables, function calls, lists, hashes, methods, etc.
  • Whenever there is no equivalent Python function for a Perl function, the function is emulated using the included Python library.
  • Warns about variables with same name but different type within a scope, eg. when using a name for both a hash and a scalar (%foo, $foo). This included scalars, hashes, lists, arrays and (hopefully) filehandles.
  • Warns about mixing variables with same name but different Perl scoping within a Python scope, eg. using (global) $foo and my $foo in one scope.
  • Strips statements like 'my ($foo, %bar);'; this is: my and local declarations without assignment.
  • Special variables are renamed to their equivalent within the included Python library.
  • 'here-documents' are supported.

Limitations

  • Does not yet support 'use', 'BEGIN', 'END', etc. This is due how Perl handles these expressions: they get executed while parsing. See the Tutorial for solving this problem.
  • Does not handle 'bless', 'packages', etc.
  • References may or may not be resolved correctly.
  • Does not convert things like 'my ($self, arg1, arg2) = @_;' into a pythonic argument-lists. (Hey, this would be a great feature!)
  • In some rare cases Perl functions are converted to the nearly-equivalent Python function instead of using a emulated function. This is done for functions which return a value which is probly not often used.
  • The Python libary included contains all required functions, while many of them are not yet implemented.
  • Formats are not supported anyhow. (But I already have an idea how this could be done: use a class perl.Format thatfore.) This also includes the function 'write'.
  • Separate prototype declarations are not supported, whereas prototypes at function definitions are taken over (as comments).
  • Prefix/postfix operator are not resolved.
  • Esoteric execution orders are not supported (see test/weird_contexts.pl).
  • The Python libary included is not thread-save -- and probably will never become thread-save.
  • A lot more :-)

Requirements

  • For converting Perl to Python you need a running Perl installations. I tried Perl 5.6.0 on a Linux box, but every other Perl5 should work, too.
  • For running the converted source you need to at least Python 2.2.

Credits

  • The compiler back-end 'B::Bridgekepper.pm' is based on 'B::Deparse.pm' written by Stephen McCamant.
  • The runtime Python package was inspired by 'pyperlish' written by Harry George.

Interested?

The bad news: Unfortunatly, there is no way to 'try out' bridgekeeper. It's simply not available for puchasing.

The good news:But we can offer you consultancy for this conversion (where we will use bridgekeeper as a mighty tool). If you are interested in hireing me for a project, please drop me a note.

Another good news:We plan to offer a conversion service, much like we to for decompyle. But this will still take some time for settling down the code.


© Copyright 2004 · Hartmut Goebel, 09/03/04