我想在某些具有日语上下文的文件组中搜索一个单词(日语)。
我试图像普通文件一样做,但我在第 no --print statement line 的行中遇到了像宽字符这样的错误。
我用了
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