perlquestion
fireblood
<p>Hello, I'm trying to use STDIN first to read from the output of the previous process and then to read from the terminal. According to <a href=http://perldoc.perl.org/perlop.html#I%2fO-Operators>http://perldoc.perl.org/perlop.html#I%2fO-Operators</a> I should be able to do this:</p>
<p>"The <> symbol will return undef for end-of-file only once. If you call it again after this, it will assume you are processing another @ARGV list, and if you haven't set @ARGV , will read input from STDIN."</p>
<p></p>
<p>That's what I need! My simplified program, called <code>pgm</code>, is the following:</p>
<code>
#!/opt/local/tools/bin/perl
use 5.24.0;
use strict;
use warnings;
my $response;
unless (-t STDIN)
{
while (<STDIN>)
{
chomp;
print "input line is $_\n";
}
}
print "Now enter something: ";
$response = <>;
print "You entered -->", $response, "<--\n";
</code>
<p>and I invoke it as follows:</p>
<code>echo Hello | pgm</code>
<p>But it doesn't wait for anything to be entered at the <>:</p>
<code>
echo Hello | pgm
input line is Hello
Use of uninitialized value $response in print at /userdata/cfor/utils/worklib/pgm line 25.
Now enter something: You entered --><--
</code>
<p>Wouldn't the <code>while (<STDIN>)</code> end because it encountered EOF, after which it should then read input from STDIN?</p>