<?xml version="1.0" encoding="windows-1252"?>
<node id="171" title="perlfunc:getc" created="1999-08-24 18:41:45" updated="2005-08-12 19:03:33">
<type id="119">
perlfunc</type>
<author id="114">
gods</author>
<data>
<field name="doctext">
</field>
<field name="name">

&lt;P&gt;
getc - get the next character from the filehandle

&lt;P&gt;
&lt;HR&gt;
</field>
<field name="synopsis">

&lt;P&gt;
getc 
&lt;FONT SIZE=-1&gt;FILEHANDLE&lt;/FONT&gt;

&lt;P&gt;
getc

&lt;P&gt;
&lt;HR&gt;
</field>
<field name="description">

&lt;P&gt;
Returns the next character from the input file attached to 
&lt;FONT SIZE=-1&gt;FILEHANDLE,&lt;/FONT&gt; or the undefined value at end of file, or if there was an error. If 
&lt;FONT SIZE=-1&gt;FILEHANDLE&lt;/FONT&gt; is omitted, reads from 
&lt;FONT SIZE=-1&gt;STDIN.&lt;/FONT&gt; This is not particularly efficient. It cannot be used to get unbuffered single-characters, however. For that, try something more like:

&lt;P&gt;
&lt;PRE&gt;    if ($BSD_STYLE) {
        system &amp;quot;stty cbreak &amp;lt;/dev/tty &amp;gt;/dev/tty 2&amp;gt;&amp;amp;1&amp;quot;;
    }
    else {
        system &amp;quot;stty&amp;quot;, '-icanon', 'eol', &amp;quot;\001&amp;quot;;
    }
&lt;/PRE&gt;
&lt;P&gt;
&lt;PRE&gt;    $key = getc(STDIN);
&lt;/PRE&gt;
&lt;P&gt;
&lt;PRE&gt;    if ($BSD_STYLE) {
        system &amp;quot;stty -cbreak &amp;lt;/dev/tty &amp;gt;/dev/tty 2&amp;gt;&amp;amp;1&amp;quot;;
    }
    else {
        system &amp;quot;stty&amp;quot;, 'icanon', 'eol', '^@'; # ASCII null
    }
    print &amp;quot;\n&amp;quot;;
&lt;/PRE&gt;
&lt;P&gt;
Determination of whether &lt;CODE&gt;$BSD_STYLE&lt;/CODE&gt; should be set is left as
an exercise to the reader.

&lt;P&gt;
The &lt;CODE&gt;POSIX::getattr()&lt;/CODE&gt; function can do this more portably on systems purporting 
&lt;FONT SIZE=-1&gt;POSIX&lt;/FONT&gt; compliance. See also the &lt;CODE&gt;Term::ReadKey&lt;/CODE&gt; module from your nearest 
&lt;FONT SIZE=-1&gt;CPAN&lt;/FONT&gt; site; details on 
&lt;FONT SIZE=-1&gt;CPAN&lt;/FONT&gt; can be found on
 [%linkNodeTitle "perlman:perlmod|CPAN", $NODE, "CPAN",{anchor=&gt;"CPAN"};%].

&lt;HR&gt;
</field>
</data>
</node>
