Mailing List Archive


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

Re: [tlug] perl/curses/utf8



Hi s.

On 2011/08/07 1:06, s smith wrote:

use Curses;
use Encode qw(encode decode);
binmode(STDOUT, ':utf8');
I would have replaced this line:
my $str = decode 'utf8', 'よろしく、世界';
with:
use utf8; # tells Perl that this source code contains utf8 characters
my $str = 'よろしく、世界';
my $octats = encode 'UTF-16', $str;

now $octats contain a byte-data with UTF-16 encoding.
Of course, you need to know if printw expects UTF-16, UTF-32, Little or Big endiens.
to qoute to documentation:
To find how (UCS-2|UTF-(16|32))(LE|BE)? differ from one another, see Encode::Unicode.

print $str, "\n";
sleep 5;
initscr();
printw("Hello world!\n");
of course, change here to $octats:
printw($str);
refresh();
getch();
endwin();

encodings are always a problem, and you always need to keep an eye on in which encoding you get the data, in which encoding it is being kept by the program, and in which encoding the output is expected. get any step wrong, and you will see gibbrish.

good luck.

Shmuel.

Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links