0
我要搜索的单词(在日本)在一些组文件中的哪一个具有日本上下文。如何使用perl脚本读取有日文上下文的文件?
我试图做正常的文件,但是我得到错误,如在线路宽字符打印没有--print语句行。
我用
use Unicode::Japanese;
use Unicode::Japanese qw(PurePerl);
在一些网站给出。
这里是我使用
my $dr="My_Directory" ;
opendir DIR, $dr ;
my @txtfiles=grep { /\.txt$/ } readdir(DIR) ;
foreach $file(@txtfiles)
{
my $count=0;
my @words=();
open(FILE, $dr.$file);
while (<FILE>)
{
push(@words, split(/\s+/));
}
foreach $word (@words)
{
if($word=~ m/$word_to_search/i)
{
$count++;
}
}
print "$word_to_search occurs $count times in $file file\n";
}
任何想法将是巨大的有用的代码。
在此先感谢。
PNVR
你会得到什么错误?该文件在哪个编码中? – Johnny 2011-02-03 10:30:27