Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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

by Caillte (Friar)
on Mar 12, 2001 at 06:22 UTC ( [id://63717]=note: print w/replies, xml ) Need Help??


in reply to How can I get just one character from STDIN?

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").

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-20 02:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found