I am learning perl Inline::Python library. In the example of cpan website, we have
print "9 + 16 = ", add(9, 16), "\n";
print "9 - 16 = ", subtract(9, 16), "\n";
use Inline Python => <<'END_OF_PYTHON_CODE';
def add(x,y):
return x + y
def subtract(x,y):
return x - y
END_OF_PYTHON_CODE
Is it possible to put python code into string so that I can create the python code in the runtime? For example, something like:
my $python_code = "
def add(x,y):
return x + y
";
print $python_code;
use Inline Python => "$python_code";
print "9 + 16 = ", add(9, 16), "\n";
We have a projects that will dynamically create python functions at the runtime. And we want to call these functions. Is py_eval() the way to go? Thanks in advance.