in reply to Multiple STDIN sources

Basically, perl blows right past the "my $ans = <STDIN>;" line.
Really? Not for me. I've added the following lines before your exit:
chomp $ans; print "Got '$ans'\n"; print "stream = $stream";
And this is what I get when running:
$ ./stdin foo bar ^D Do you want to process the stream?yes Got 'yes' stream = foo bar $

Abigail

Replies are listed 'Best First'.
Re: Re: Multiple STDIN sources
by The Mad Hatter (Priest) on Mar 10, 2004 at 00:29 UTC
    This is because it isn't reading it from a pipe in your test: it's reading it all from user input (as you typed in text followed by a control-D). If you do something like echo foo | ./stdin it does blow right past the prompt like the OP said.
      Oh, I see. In that case, just reopen STDIN, and read from the terminal:
      #!/usr/bin/perl -w use strict; $| = 1; my $stream; while (<>) { $stream .= $_; } open STDIN, "/dev/tty" or die; print "Do you want to process the stream? "; my $ans = <STDIN>; chomp $ans; print "Got '$ans'\n"; print "stream = $stream"; #... exit; __END__ $ echo foo | ./stdin Do you want to process the stream? yes Got 'yes' stream = foo $
      Abigail