How do I capture Chinese input via SCIM with STDIN in Perl?

Posted by KCArpe on Stack Overflow See other posts from Stack Overflow or by KCArpe
Published on 2010-05-22T04:44:29Z Indexed on 2010/05/22 15:00 UTC
Read the original article Hit count: 193

Filed under:
|
|
|

I use SCIM on Linux for Chinese and Japanese language input. Unfortunately, when I try to capture input using Perl's STDIN, the input is crazy. As roman characters are typed, SCIM tries to guess the correct final characters.

^H (backspace) codes are used to delete previously suggested chars on the command line. (As you type, SCIM tries to guess final Asian chars and displays them.) However, these backspace chars are shown literally as ^H and not interpreted correctly.

Example one-liner:

perl -e 'print "Chinese: "; my $s = <STDIN>; print $s'

When I enable SCIM Chinese or Japanese language input, as I type, e.g., nihao => ??, here is the result:

?^H?^H?^H?^H?^H??^H^H??^H^H??^H^H??^H^H??^H^H??^H^H??^H^H??^H^H??^H^H??

At the very end of this string, you can see "??" (nihao/hello). At a normal bash prompt, if I type nihao (with Chinese enabled), the results is perfect.

This has something to do with interpretation of backspace chars (or control chars) during Perl's STDIN. The same thing happens when using command 'read' in Bash.

Witness: read -p 'Chinese: ' s && echo $s

© Stack Overflow or respective owner

Related posts about perl

Related posts about bash