0

I have a Perl script that runs a python script but i need to pass information back to the Perl script. Anyone can help me to achieve this?

This is my code so far

open(my $py, "|-", "python2 /home/pi/myRead.py") or die "Cannot run Python script: $!";
while (<$py>) {
    $newCard = $py;
}
close($py);
3
  • You keep overwriting $newCard instead of appending to it Commented Aug 30, 2017 at 18:34
  • stackoverflow.com/questions/10765311/… Commented Aug 30, 2017 at 18:35
  • 1
    "-|" is for reading. Commented Aug 30, 2017 at 18:37

1 Answer 1

3
my $newCard = `python2 /home/pi/myRead.py`;
Sign up to request clarification or add additional context in comments.

7 Comments

I swear this was my first try and didn't work. worked now. TY
Don't use backticks. Use qx. eg. my $newCard = qx@ python /home/pi/myRead.py@;
@William Pursell, Why??? `...` is short for qx`...`, which is short for readpipe(qq`...`).
@William Pursell, You could argue that qx(...) is more readable, but that's not what you recommended.
Argue on what basis? qq@@ adds noise, unfamiliarity and complexity, all deterrents to readability. On top of that, it changes the meaning of @, a huge reduction in readability. Finally, qq@@ also reduces usability (by preventing the interpolation of arrays). All that, and no benefits are added. It clearly hurts readability (and usability). /// On the other hand, qq() also adds noise and unfamiliarity, but also adds balanced delimiters which adds a modicum of readability. Enough to overcome the noise and unfamiliarity? debatable.
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.