Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2014-07-26 06:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls