Perlでのutf-8による日本語処理 の変更点 - アールメカブ

アールメカブ


Perlでのutf-8による日本語処理 の変更点


例えば日本語で次のようなスクリプトを用意しておくと

 #!/usr/bin/perl

 use utf8;
 binmode(STDIN, ":utf8");
 binmode(STDOUT, ":utf8");
 use open ':utf8';

 while(<>){
 #	/(\w)/;
 	/(\p{Han})/;
 	print "$1\n";
 }
 # test.txt
 これは試行です.

これで ./utf.pl < test.txt とすると,ちゃんと「試」を補足する.

あるいは,euc-jp で書いたテキストを読み込んで処理するには

 #!/usr/bin/perl

 use utf8;
 binmode(STDIN, ":utf8");
 binmode(STDOUT, ":utf8");
 open(IN,"<:encoding(euc-jp)", $ARGV[0]);
 
 while(<IN>){
	@char = split//;
	foreach (@char){
		print;
		print "\n";
	}
 }




以下が参考になる.
 http://module.jp/blog/regex_unicode_prop.html



* 1. もくじ [#c0e38d35]

#contents
 * 1. もくじ