perlfunc
gods
<P>
getc - get the next character from the filehandle
<P>
<HR>
<P>
getc
<FONT SIZE=-1>FILEHANDLE</FONT>
<P>
getc
<P>
<HR>
<P>
Returns the next character from the input file attached to
<FONT SIZE=-1>FILEHANDLE,</FONT> or the undefined value at end of file, or if there was an error. If
<FONT SIZE=-1>FILEHANDLE</FONT> is omitted, reads from
<FONT SIZE=-1>STDIN.</FONT> This is not particularly efficient. It cannot be used to get unbuffered single-characters, however. For that, try something more like:
<P>
<PRE> if ($BSD_STYLE) {
system "stty cbreak </dev/tty >/dev/tty 2>&1";
}
else {
system "stty", '-icanon', 'eol', "\001";
}
</PRE>
<P>
<PRE> $key = getc(STDIN);
</PRE>
<P>
<PRE> if ($BSD_STYLE) {
system "stty -cbreak </dev/tty >/dev/tty 2>&1";
}
else {
system "stty", 'icanon', 'eol', '^@'; # ASCII null
}
print "\n";
</PRE>
<P>
Determination of whether <CODE>$BSD_STYLE</CODE> should be set is left as
an exercise to the reader.
<P>
The <CODE>POSIX::getattr()</CODE> function can do this more portably on systems purporting
<FONT SIZE=-1>POSIX</FONT> compliance. See also the <CODE>Term::ReadKey</CODE> module from your nearest
<FONT SIZE=-1>CPAN</FONT> site; details on
<FONT SIZE=-1>CPAN</FONT> can be found on
[%linkNodeTitle "perlman:perlmod|CPAN", $NODE, "CPAN",{anchor=>"CPAN"};%].
<HR>