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 http://perldoc.perl.org/perlop.html#I%2fO-Operators I should be able to do this:
"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."
That's what I need! My simplified program, called pgm, is the following:
#!/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";
and I invoke it as follows:
echo Hello | pgm
But it doesn't wait for anything to be entered at the <>:
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 --><--
Wouldn't the while (<STDIN>) end because it encountered EOF, after which it should then read input from STDIN?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.