Python module for calling perl functions from python. Just declare and decorate an empty python function and it will invoke your perl function and return the results.
Read more at: https://www.boriel.com/calling-perl-from-python.html
First create a small Perl script named mymodule.pl:
sub myfunc
{
my ($a, $b) = @_;
return $a + $b;
}
1;Now let's create a Python program that will invoke
the function myfunc() in the module mymodule.pl:
from perlfunc import perl5lib, perlfunc, perlreq
@perlfunc
@perlreq('mymodule.pl')
def myfunc(a, b):
pass # Empty body
print(myfunc(1, 3)) # Should print 4Explanation:
- First we import the decorators.
- Then we create an empty (notice the
passkeyword) functionmyfuncwith the same parameters as the called function. - Finally we wrap the function using two decorators,
@perlreqand@perlfunc
Now we can call our python function myfunc(a, b) and the Perl one will be called. :)
perlfunc: mandatory. Use it to invoke a perl function with the same name as the python function.perlreq(<perl script>): imports the required module where the perl function is defined.perl5lib: optional, defines a list of path to be added to thePERL5LIBpath env var.