Manual

- Overview
- Tutorials
- FAQs
- History / Changes
- License

Reference

- Language
- Functions
- Operators
- Special Variables
- Pragmas
- Utilities
- Internals
- Platform Specific

Modules

- A • B • C • D • E
- F • G • H • I • L
- M • N • O • P • S
- T • U • X

News / Blogs

- Perl Buzz
- Perl Iron Man
- Perlsphere
- Planet Perl
- TPF news
- Use Perl

See also

- CPAN
- Perl.org
- Perl.com
- Perl 5 Wiki
- Perl Jobs
- Perl Mongers
- Perl Monks

Contact

- Site designed and maintained by Jon Allen (JJ)
- http://perl.jonallen.info

- View the project page and FAQs

# getc

Perl 5 version 10.1 documentation
Go to top

# getc

Perl functions A-Z | Perl functions by category | The 'perlfunc' manpage

- 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 (in the latter case `$!` is set). If FILEHANDLE is omitted, reads from STDIN. This is not particularly efficient. However, it cannot be used by itself to fetch single characters without waiting for the user to 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 null    }    print "\n";

  Determination of whether $BSD_STYLE should be set is left as an exercise to the reader.

  The `POSIX::getattr` function can do this more portably on systems purporting POSIX compliance. See also the `Term::ReadKey` module from your nearest CPAN site; details on CPAN can be found on "CPAN" in perlmodlib.

Recently read

Tools

- Preferences