good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: getc vs readlineby dave_the_m (Monsignor) |
on Nov 30, 2019 at 19:57 UTC ( [id://11109490]=note: print w/replies, xml ) | Need Help?? |
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.
In Section
Seekers of Perl Wisdom
|
|