Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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.

Replies are listed 'Best First'.
Re^2: STDIN problemo
by ikegami (Patriarch) 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
Domain Nodelet?
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 lurking in the Monastery: (1)
As of 2023-09-28 00:13 GMT
Find Nodes?
    Voting Booth?

    No recent polls found