Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: getc vs readline

by dave_the_m (Monsignor)
on Nov 30, 2019 at 19:57 UTC ( #11109490=note: print w/replies, xml ) Need Help??


in reply to getc vs readline

getc() uses the same input buffer as readline. getc() won't normally return after a single character like 'X' is entered; it waits until a whole line has been entered (including \n), then returns the first character of it. readline() sees the remainder of the line still in the buffer and returns immediately. For example, if the user types "abc\n", then at the point the user presses carriage-return, getc() returns "a" and readline() immediately follows on returning "bc\n".

If you truly want to get the next character even if the user hasn't pressed return yet, then look into something like Term::ReadKey.

Dave.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2020-10-19 15:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (205 votes). Check out past polls.

    Notices?