Perl: How do I capture Chinese input via SCIM with STDIN?
- by KCArpe
Hi,
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
Cheers,
Kevin