How can I use the Perl module from Python?

There is a Perl module that provides perfect functionality for my Python application. Is there any way to use it? (it’s complicated , it will take me a month to port it)

I do not want to run a subprocess for each use, since I need it several hundred thousand times (this is a specific type of data analyzer).

Thank you for your advice.

EDIT: requested module. This is Mail :: DeliveryStatus :: BounceParser . It corresponds to mail delivery notifications in the list of lines, which may indicate a rebound of mail. (It runs DSN body / headers through a ton of regular expressions as well as other tests. This is a serious awesome module.)

+4
source share
4 answers

I'm not sure if this is still active, but PyPerl might interest you

Most data parsers in python should still be supported. It would be nice if you could point to the parser you are looking at.

Alternatively, you can create a complete process with this perl module and use IPC mechanisms, sockets to transfer data and results back and forth from your python and perl processes.

+5
source

I know that you can use Python in Perl with Inline::Python , but that is not your question. Python may have similar functionality. Perhaps something like perlmodule ?

+2
source

I would use something like HTTP :: Server :: Simple to create a local web service. Then you just need to make requests against this. This is still an external process, but it is only one.

+1
source

I do not want to run a subprocess for each use, since I need it several hundred thousand times (this is a special type of data analyzer).

Bad politics. Linux base shells do this deployment process all the time. Preventing spawning is a bad limitation.

However, you can do this trivially.

 python prepare_data.py | perl my_magic_module.pl | python whatever_else.py 

Wrap your magic module in a simple perl script that reads from stdin, does the magic thing, and writes to stdout.

Divide your Python into two parts: the part is done before the perl call and the part that is executed after the perl call.

Assemble a high-performance conveyor that (a) performs all three steps at the same time and (b) does not develop many processes.

This, BTW, will also use your every core.

-3
source

All Articles