I'm guessing that this bit in your post was just by way of example:
print "Do you want to process the stream?"; my $ans = <STDIN>;
I mean, you wouldn't really need that sort of prompt in a real script: if the person didn't want to process the stream, they wouldn't run the program in the first place, so why ask this kind of question at all? I could imagine many cases where the user needs to provide some kind of decision about how the stream should be processed, and maybe sometimes the user needs some sort of report about the stream before making the decision.

As a rule, stream-based processes handle user input by means of command-line options or flags (e.g. "-q" to suppress warnings or progress reports, "-f" to continue processing despite warnings, "-r" to randomize the output, or whatever...) This is perfectly sensible in the typical case where the user is able to decide, before starting the process, what sort of option they want to use on the given run. If the user needs some info about the stream before making the decision, this might require a separate run, using the script in "probe" or "no_op" mode (or running a separate reporting script on the stream) to get the needed information before doing the processing run with their decision provided on the command line.

On a separate note, you might save some run-time if you change this:

while (<>) { $stream .= $_; }
to this:
{ local $/ = undef; $stream = <>; # slurp all the data in one read }

In reply to Re: Multiple STDIN sources by graff
in thread Multiple STDIN sources by perlfan

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.