Cari di Perl 
    Perl User Manual
Daftar Isi
(Sebelumnya) Declare a picture format with ...Output a list to a filehandle (Berikutnya)
Input and output functions

Get the next character from the filehandle

Daftar Isi

  • getc FILEHANDLE

  • 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:

    1. if ($BSD_STYLE) {
    2. system "stty cbreak </dev/tty >/dev/tty 2>&1";
    3. }
    4. else {
    5. system "stty", '-icanon', 'eol', "\001";
    6. }
    7. $key = getc(STDIN);
    8. if ($BSD_STYLE) {
    9. system "stty -cbreak </dev/tty >/dev/tty 2>&1";
    10. }
    11. else {
    12. system 'stty', 'icanon', 'eol', '^@'; # ASCII NUL
    13. }
    14. 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::ReadKeymodule from your nearest CPAN site; details on CPAN can be found underCPAN in perlmodlib.

 
Source : perldoc.perl.org - Official documentation for the Perl programming language
Site maintained by Jon Allen (JJ)     See the project page for more details
Documentation maintained by the Perl 5 Porters
(Sebelumnya) Declare a picture format with ...Output a list to a filehandle (Berikutnya)