Pretend that this is your old program asking the questions. It doesn't do anything except ask them, read the answers and print out the names it read:

#! perl -slw use strict; print "enter file name (you must specify the file name and press Ente +r)"; chomp( my $infile = <STDIN> ); print "do you want to specify another file name (Y/N) (you must enter +N in most cases and press Enter)"; chomp( my $another = <STDIN> ); print "enter name for output file (you must specify a name for the out +put file, eg ttt and press Enter)"; chomp( my $outfile = <STDIN> ); print "reading $infile; writing $outfile"; exit 99;

Then you can drive that program from perl using something like this:

#! perl -slw use strict; my $progname = 'junk33'; my $pid = open CMD, '|-', $progname or die $!; print CMD 'myInfile'; print CMD 'N'; print CMD 'myOutfile'; close CMD; waitpid $pid, 0; print "$progname ended: status: ", $? >>8;

And when you run that, you'll see:

c:\test>junk32 enter file name (you must specify the file name and press Enter) do you want to specify another file name (Y/N) (you must enter N in mo +st cases and press Enter) enter name for output file (you must specify a name for the output fil +e, eg ttt and press Enter) reading myInfile; writing myOutfile junk33 ended: status: 99

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy

In reply to Re: "Answer" questions in an interactive program? by BrowserUk
in thread "Answer" questions in an interactive program? by Anonymous Monk

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.