Perl: the Markov chain saw | |
PerlMonks |
output from an external programby olecs (Scribe) |
on Dec 01, 2005 at 13:34 UTC ( [id://513262]=perlquestion: print w/replies, xml ) | Need Help?? |
olecs has asked for the wisdom of the Perl Monks concerning the following question:
Hello everyone,
I am looking for a way to open an external program, feed a set of data to it and capturing the output in a variable, much like using @var = `extprog blah blaha` - extprog returns a set of values each time it gets input. The problem is that I have a lot of data (several million sets of coordinates) and it takes a bit of time to open and initialize the external program each time, hence I would like to open the external program once and feed the data through a pipe into the program, I was imagining something like this: (note that the code might have errors, just showing for illustration)
Now, my external program will get this data and put it's data on stdout. The question is how do I get hold of/redirect the output, preferrably without resorting to temporary files. rgds, Ole C. Update I got this sorted now, thanks for the replies. I also got a couple of requests to share my final code and what I ended up doing in the end, so I will post it here. The output from my external program was buffered, so I could not use open3 as the read/write deadlocked. Hence I ended up using brother merlyns suggestion which at first seemed like pure magic but which made more sense after reading up on -| My final code for achieving what I wanted then looked like this:
Back to
Seekers of Perl Wisdom
|
|