Documentation for method getc, assembled from the following types:
method getc(IO::Handle: --> Str)multi sub getc (IO::Handle = --> Str)
Reads a single character from the input stream. Attempting to call this method when the handle is in binary mode will result in
X::IO::BinaryMode exception being thrown. The subroutine form defaults to
$*ARGFILES if no handle is given. Returns
Nil, if no more input is available, otherwise operation will block, waiting for at least one character to be available; these caveats apply:
Using getc to get a single keypress from a terminal will only work properly if you've set the terminal to "unbuffered". Otherwise the terminal will wait for the return key to be struck or the buffer to be filled up before perl6 gets even a single byte of data.
If your handle's encoding allows combining characters to be read, perl6 will wait for more data to be available before it provides a character. This means that inputting an "e" followed by a combining acute will give you an e with an acute rather than giving an "e" and letting the next reading function give you a dangling combiner. However, it also means that when the user inputs just an "e" and has no intention to also input a combining acute, your program will be waiting for another keypress before the initial "e" is returned.
method getc(IO::CatHandle: --> Bool)
Returns a single character of input from the handle. All the caveats described in
IO::Handle.getc apply. Returns
Nil when there is no more input. It is an error to call this method when the handle is in binary mode, resulting in
X::IO::BinaryMode exception being thrown.
(my = 'foo'.IO).spurt: 'I ♥ Perl';(my = 'bar'.IO).spurt: 'meow';my = IO::CatHandle.new: , ;.say while = .getc; # OUTPUT: «I␤ ␤♥␤ ␤P␤e␤r␤l␤m␤e␤o␤w␤»