chakreey has asked for the wisdom of the Perl Monks concerning the following question:
Hello PerlMonks,
I need your advise on giving input and collecting output from a perl script using another perl script.
Here is a description of what I am trying to do:
I am using someone else's perl script compare.pl (This script is part of a package, that contains two *.pl files, six *.pm files and 5 text files). compare.pl takes input form STDIN and gives out put as a text file. I need to run compare.pl many times and collect all output text files for further processing.
Now, I wrote a short perl script that 1) calls compare.pl program, 2) gives input to it, 3) reads generated output-text-file and 4) stores output-text-file-data in memory. When this is finished, my script calls compare.pl once again and the sequence (1-2-3-4) repeats for n-times.
I personally feel, writing output of compare.pl to hard disc and reading output-file from hard disc is a time consuming and inefficient process. I would rather like to call compare.pl from my script, give input to it, save output in memory (as a 2 dimensional array, with every sub-array containing output of single run of compare.pl) and finally write all contents of 2 dimensional array to a text or csv file.
How should I do it ?
compare.pl has a hidden answer to my query. This script, compare.pl calls other programs in the package (*.pm files), gives input and takes output through Exporter function. I am thinking, should I modify compare.pl to compare.pm and use the same method to give input and collect output OR should I use IPC::open(3) to call compare.pl, give input and collect output ?
I have not created any library till now, and have not used any perl module either. Any suggestions ?
TIA
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to give input and collect output of a perl script using another perl script
by GrandFather (Saint) on Mar 23, 2011 at 10:05 UTC | |
by chakreey (Acolyte) on Mar 23, 2011 at 13:16 UTC | |
by GrandFather (Saint) on Mar 23, 2011 at 20:02 UTC | |
by chakreey (Acolyte) on Apr 07, 2011 at 10:09 UTC | |
by Anonymous Monk on Mar 23, 2011 at 14:11 UTC | |
by chakreey (Acolyte) on Mar 23, 2011 at 15:57 UTC | |
by GrandFather (Saint) on Mar 23, 2011 at 19:34 UTC |