[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[FWP] ReadKey and multiple-byte characters



This is probably elementary to you geniuses, but I
want to bring up something unusual I found.

Using Term::ReadKey as the following:

ReadMode('cbreak');
$a = ReadKey(0);
ReadMode('normal');

print length($a) . "\n";
print ord($a) . "\n";
print \$a . "\n";

This is fine using normal keyboard keys, for example
the letter 'a':
1
97
SCALAR(0x140047390)

But using the left arrow key:
1
27
SCALAR(0x140047390)
1
91
SCALAR(0x140047390)
1
68
SCALAR(0x140047390)

So, <esc>[C is a left arrow, okay.

It seems to me that it's treating the return value as
a single string and 3 strings at the same time, which
is completely beyond my grasp.

You can also assign the return value of ReadKey(0) to
an array. You get an array of length 1, but you can
iterate through the array as if it contained three
discrete values.

Please enlighten me, while trying not to make me feel
too ignorant. :-)

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe