| Input and output functionsGet the next character from the filehandleDaftar Isi - getc
Returns the next character from the input file attached to FILEHANDLE,or the undefined value at end of file or if there was an error (inthe latter case $! is set). If FILEHANDLE is omitted, reads fromSTDIN. This is not particularly efficient. However, it cannot beused by itself to fetch single characters without waiting for the userto hit enter. For that, try something more like: - if ($BSD_STYLE) {
- system "stty cbreak </dev/tty >/dev/tty 2>&1";
- }
- else {
- system "stty", '-icanon', 'eol', "\001";
- }
- $key = getc(STDIN);
- if ($BSD_STYLE) {
- system "stty -cbreak </dev/tty >/dev/tty 2>&1";
- }
- else {
- system 'stty', 'icanon', 'eol', '^@'; # ASCII NUL
- }
- print "\n";
Determination of whether $BSD_STYLE should be setis left as an exercise to the reader. The POSIX::getattr function can do this more portably onsystems purporting POSIX compliance. See also the Term::ReadKey module from your nearest CPAN site; details on CPAN can be found underCPAN in perlmodlib. |
| |
|