I'm sure I'm doing something silly OR maybe it's my terminal emulator, though I'm using standard putty. I'm real stumped and am hoping someone can spot my problem...
The attached piece of code simply uses ReadKey to do single char I/O and echo its binary character value.
When there's input, I print ">>> GOT INPUT". Then I read it and print its value. If I type 8900098 the following is what I see:
root@poker collectl# ./sht.pl
>>> GOT INPUT
INPUT: 56
>>> GOT INPUT
INPUT: 57
>>> GOT INPUT
>>> GOT INPUT
>>> GOT INPUT
>>> GOT INPUT
INPUT: 57
>>> GOT INPUT
INPUT: 56
so what happened to the echos of the '0's? Here's the code that does it:
#!/usr/bin/perl -w
use Term::ReadKey;
use IO::Select;
ReadMode 4;
my $sel=new IO::Select(STDIN);
my $ctrlCFlag=0;
while (!$ctrlCFlag)
{
while(my @ready = $sel->can_read(1))
{
foreach my $filehandle (@ready)
{
if ($filehandle eq 'STDIN')
{
print ">>> GOT INPUT\n";
while (my $char=ReadKey -1)
{
my $byte=unpack('C', $char);
printf "INPUT: %d\n", $byte;
if ($byte==3)
{
$ctrlCFlag=1;
last;
}
}
}
}
}
}
ReadMode 0;
can_read() says there's something to be read on STDIN but ReadKey isn't see anything. And what's so special about '0'? Isn't it just another key?
Any and all help will be greatly appreciated.
-mark
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.