作者: 藤岡和夫
日時: 2004/7/09(21:18)
On Fri, 09 Jul 2004 19:16:33 +0900
"Bruce." <kbk@...> さんwrote:

> 今日、Perl(ActivePerl 5.8.4 Build 810)をいじっていて気がついたこと。
> 
> C:\home\work>echo 漢字|perl -Mencoding=sjis -ne "print if /\p{InBasicLatin}+/"
> 漢字
> 
> C:\home\work>echo 漢字|perl -ne "print if /\p{InBasicLatin}+/"
> 
・・・
> もっと引っかかったのは
> 
> C:\home\work>echo 漢字|perl -Mencoding=sjis -ne "print if /[[:ascii:]]+/"
> 漢字
> 
> C:\home\work>echo 漢字|perl -ne "print if /[[:ascii:]]+/"
> 漢字
> 
> C:\home\work>echo 漢字|perl -Mencoding=sjis -ne "print if /[[:alnum:]]+/"
> 漢字
> 
> C:\home\work>echo 漢字|perl -ne "print if /[[:alnum:]]+/"
> 
> 何じゃこの結果は・・・
> 

 次のようにして試してみました。

use encoding "Shift_JIS";
$str = "漢字";
print "alpha:", $str,"\n" if $str =~ /[[:alpha:]]+/;
print "alnum:", $str,"\n" if $str =~ /[[:alnum:]]+/;
print "ascii:", $str,"\n" if $str =~ /[[:ascii:]]+/;
print "blank:", $str,"\n" if $str =~ /[[:blank:]]+/;
print "cntrl:", $str,"\n" if $str =~ /[[:cntrl:]]+/;
print "digit:", $str,"\n" if $str =~ /[[:digit:]]+/;
print "graph:", $str,"\n" if $str =~ /[[:graph:]]+/;
print "lower:", $str,"\n" if $str =~ /[[:lower:]]+/;
print "print:", $str,"\n" if $str =~ /[[:print:]]+/;
print "punct:", $str,"\n" if $str =~ /[[:punct:]]+/;
print "space:", $str,"\n" if $str =~ /[[:space:]]+/;
print "upper:", $str,"\n" if $str =~ /[[:upper:]]+/;
print "word:", $str,"\n" if $str =~ /[[:word:]]+/;
print "xdigit:", $str,"\n" if $str =~ /[[xdigit:]]+/;
print "InBasicLatin:", $str,"\n" if $str =~ /\p{InBasicLatin}+/;

 結果は、

C:\Scripts\Perl>perl 5_8test.pl
alpha:漢字
alnum:漢字
graph:漢字
print:漢字
word:漢字

でした。コマンドラインからパイプで受け取るのと違う?

藤岡 和夫
FGALTS@...
kazuf@...
TS Networkのために http://homepage1.nifty.com/kazuf/