วันอาทิตย์ที่ 22 กรกฎาคม พ.ศ. 2555

[perl] How to write file with UTF-8

In the environment:
export PERL_UNICODE=SDL



on the commandline:
perl -CSDL -le 'print "\x{1815}";



or with binmode:
binmode(STDOUT, ":utf8");          #treat as if it is UTF-8
binmode(STDIN, ":encoding(utf8)"); #actually check if it is UTF-8



or with PerlIO:

open my $fh, ">:utf8", $filename
    or die "could not open $filename: $!\n";

open my $fh, "<:encoding(utf-8)", $filename
    or die "could not open $filename: $!\n";



or with the open pragma:
use open ":encoding(utf8)";
use open IN => ":encoding(utf8)", OUT => ":utf8";



#Cr. http://stackoverflow.com/questions/627661/how-can-i-output-utf-8-from-perl

ไม่มีความคิดเห็น:

แสดงความคิดเห็น