1

I have one script in Perl and the other in Python. I need to get the results of Perl in Python and then give the final report. The results from Perl can be scalar variable, hash variable, or an array.

Please let me know as soon as possible regarding this.

2
  • Why not fix the perl script to be in Python? Sounds simpler. What's the problem that makes it hard to replace the perl? Commented Apr 30, 2009 at 10:27
  • Perhaps you want the answer to How can I read Perl data structures from Python? Commented Jun 5, 2020 at 21:51

3 Answers 3

6

Use the subprocess module to run your Perl script to capture its output:

You can format the output however you choose in either script, and use Python to print the final report. For example: your Perl script can output XML which can be parsed by the Python script and then printed using a different format.

Sign up to request clarification or add additional context in comments.

Comments

3

Take a look at PyYAML in Python and YAML in Perl.

Comments

2

You could serialize the results to some sort of a string format, print this to standard output in the Perl script. Then, from python call the perl script and redirect the results of stdout to a variable in python.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.