http://www.perlmonks.org?node_id=335294

perlfan has asked for the wisdom of the Perl Monks concerning the following question:

I have a script that I want to direct an input stream to using either "|":
% cat myfile.txt | myprogram.pl
or "<":
% myprogram.pl < myfile.txt
The problem I have is that in the code I also ask for user input, and assign the answer to the question using <STDIN>. However the STDIN stream conflict, and I can not figure out how to "reset" STDIN. Here is my code that shows the problem:
#!/usr/bin/perl -w use strict; my $stream; while (<>) { $stream .= $_; } print "Do you want to process the stream?"; my $ans = <STDIN>; #... exit;
Basically, perl blows right past the "my $ans = <STDIN>;" line. I have searched high and low - both here and on the web, and can not find the solution - do I need to reset STDIN? Doing a "close(STDIN)" causes errors, so I am not sure what to do. Thanks! Brett