Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: STDIN problemo

by eye (Chaplain)
on Dec 20, 2009 at 07:16 UTC ( #813592=note: print w/ replies, xml ) Need Help??

in reply to STDIN problemo

Update: I got that wrong. See the correct explanation from ikegami (below).

While the problem has been solved, it has not been explained. In the first line:

@piped = <STDIN>;
Reading <STDIN> in list context reads until the end of file for STDIN. At that point, you can no longer read from STDIN, so line 4 fails:
$user_input = <STDIN>;
The solutions suggested either avoid using STDIN for user input (reading from the console) or close and re-open STDIN.

Comment on Re: STDIN problemo
Select or Download Code
Re^2: STDIN problemo
by ikegami (Pope) on Dec 20, 2009 at 07:48 UTC
    The problem has nothing to do with reaching the end of the file. As you can see, you can keep reading from a terminal after reaching the end of the file.
    >perl -e"for my $x (1..2) { print qq{$x: $_} while <STDIN>; }" a 1: a b 1: b c 1: c ^Z d 2: d e 2: e f 2: f ^Z

    The problem is much simpler. If STDIN was redirected away from the console, then it can't be used to read from the console. The solutions provided are alternate means of accessing the console.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://813592]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2014-11-26 18:27 GMT
Find Nodes?
    Voting Booth?

    My preferred Perl binaries come from:

    Results (172 votes), past polls