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

Answer: is ther any way to get only one char from stdin

( #63717=categorized answer: print w/ replies, xml ) Need Help??

Q&A > input and output > How can I get just one character from STDIN? contributed by Caillte

Another way is:

$buf = ' '; while($buf) { sysread STDIN, $buf, 1; print "$buf\n" # or whatever else you want # to do with it ;) }

I've tested this out on linux and it works fine. Any reason why it wouldnt work on other platforms?

Editor: The problem with this method is that the sysread will hang until the user presses the RETURN key (so if the user really only enters one character and it isn't RETURN, then the program will just "hang").

Comment on Answer: is ther any way to get only one char from stdin
Download Code
Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2015-12-01 02:43 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (791 votes), past polls