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


In reply to How to give input and collect output of a perl script using another perl script by chakreey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.