I am new to perl and I have a python script which I can't understand exactly ...
OK, so we've established that you don't really understand Perl, perhaps don't really understand Python, and certainly don't understand the Python script you're dealing with.
Is it possible to take the python code and put it inside the perl script ...?
As others have pointed out, it's possible, and in more than one way. But is it wise? I have to agree with Arunbear's suggestion that your time might be better spent working to gain a better understanding of some combination of Perl, Python and the scripts in question. Your current self-described state of ignorance conjures up notions of very thin ice and very cold, dark waters beneath. Once you have improved your grasp of the issues with which you're grappling, you may find a much simpler and safer path to a solution. You may also find that the whole thing ain't broke and don't need fixing!
| [reply] |
I gotta second that motion ...
There are lots of great language interpreters out there. Python is one; Perl is another. (During the course of any given work-week, I often use both of these and several more, switching between them without pause.) It is, in fact, very common to find more than one such tool being used in a project at the same time ... and never the twain shall meet. Simply use each language for its own particular advantages (or, as the case may be, “because it is (already) there,” and ... don’t borrow trouble. You do not have a problem now. Do not make one for yourself. The present situation is quite defensible and serviceable. It needs neither remedy nor improvement.
| |
It is possible, though it seems like a false economy. Here is another method:
#!/usr/bin/perl
use autodie;
use strict;
use warnings;
my $code = do { local $/; <DATA> };
my $result = qx/python -c '$code'/;
print "$result\n";
__DATA__
def cube(x):
return x * x * x
print "the cube of 2 is %d" % cube(2)
| [reply] [d/l] |