Skip to main content.
Enero 21st, 2007  español 

Calling Perl functions from Python

Computer Science Programming

I’m currently working on a project and need to call old Perl functions from Python (until the perl code is refactorized and translated to python).

A friend of mine told me about PyPerl, but we found it’s currently unmaintained. :(

Suppose you have a perl module, named mylib.pl, which have a function like:

sub myfunc
{
my ($a, $b) = @_;
...
...

return result;
}

We wanted to be able to call myfunc function from python, without having to rewrite it.
So I managed to create a python module to wrap perl functions in python, using python decorators. With it, you can call perl functions this way:

import perlfunc

@perlfunc
@perlreq('mylib.pl')
def myfunc(a, b):
pass

This would call the perl function myfunc (defined in library mylib.pl) using a and b as parameters. Lists (and arrays as list of lists) and dictionaries can be passed as parameters (they are conveniently converted to perl).

It seems to work very well. :)
It’s licensed GPL, and you can download it from here: perlfunc.py

Comparte el artículo:These icons link to social bookmark sites which allow other readers to discover and share new webs and posts.
  • del.icio.us
  • digg
  • fresqui
  • meneame

Posted by Boriel as Computer Science, Programming

Rate This Post: 1 Stars2 Stars3 Stars4 Stars5 Stars
2 Votes | Average: 4 out of 52 Votes | Average: 4 out of 52 Votes | Average: 4 out of 52 Votes | Average: 4 out of 52 Votes | Average: 4 out of 5 (2 votes, average: 4 out of 5)

 

This entry was posted at 10.44 pm and is filed under Computer Science, Programming. You can follow any responses to this entry through the comments RSS 2.0 feed. You can leave a response, or trackback from your own site.

5 Responses to “Calling Perl functions from Python”

  1. [Spain] Arktun says:

    Estos frikis picacodigos ;)

  2. [Spain] Boriel says:

    Y no veas de la de apuros que me ha sacado. :P
    Un abrazo.

  3. [France] François Ziserman says:

    Just a test to see the protection running !

  4. [United States] Carlyle says:

    FWIW, http://wiki.python.org/moin/PyPerl
    says that
    “* Recent patches by Per Øyvind Karlsen with fixes for python 2.5 as well as some other useful stuff is available at Mandriva SVN”
    so at least one persons is working on it (good!)

  5. [Spain] Boriel says:

    Carlyle: Nice to hear that! :) Perhaps it came to late for us (at least in this project). :roll:

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Powered by WP Hashcash