如何使用 perl 脚本读取具有日语上下文的文件?
我想在一些具有日语上下文的文件组中搜索一个单词(日语) 。
我尝试像普通文件一样执行操作,但出现错误,例如 打印中的宽字符位于第 no --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
i want to search for a word(which in Japanese) in some group of files which is having Japanese context.
i tried to do as normal files, but i am getting error like wide character in print at line no --print statement line.
i used
use Unicode::Japanese;
use Unicode::Japanese qw(PurePerl);
as given in some websites.
here is the code what i am using
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";
}
any ideas will be great helpful.
Thanks in Advance.
PNVR
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请首先阅读 http://p3rl.org/UNI 并应用其中给出的建议。 编码这个话题已经在 Stack Overflow 上出现过很多次了,这根本不是日语特有的。 (Google,SO 标签,SO 搜索)
您提及您将文件保存为 UTF-8。为了让您快速入门,这是一种阅读方法:
Please first read http://p3rl.org/UNI and apply the advice given there. The topic of encoding has come many times on Stack Overflow already, this is not specific to Japanese at all. (Google, SO tags, SO search)
You mention that you saved a file as UTF-8. To get you started quickly, this is a way to read one: