我正在做中文单词之间的匹配,例如“语言中心”和大量网络文件(php、html、htm 等)。
但是,不知何故我收到以下错误:
Malformed UTF-8 character (1 byte, need 2, after start byte 0xdf) in regexp compilation at ../Final_FindOnlyNoReplace_CLE_Chinese.pl line 89, <INFILE> line 12.
任何人都可以帮忙吗?
这是我的代码。
#!/usr/bin/env perl
use Encode qw/encode decode/;
use utf8;
use strict;
use Cwd;
use LWP::UserAgent;
my($path) = @_;
## append a trailing / if it's not there
$path .= '/' if($path !~ /\/$/);
use File::Glob ':glob';
my @all_files = bsd_glob($path."*");
for my $eachFile (@all_files) {
open(INFILE, "<$eachFile") || die ("Could not open '$eachFile'\n");
my(@inlines) = <INFILE>;
my($line, $find);
my $outkey = 1;
foreach $line (@inlines) {
$find = &find($line);
if ($find ne 'false') {
chomp($line);
print "\tline$outkey : $line\n";
}
$outkey ++;
}
}
#subroutine
sub find {
my $m = encode("utf8", decode("big5", @_));
my $html = LWP::UserAgent->new
->get($m)
->decoded_content;
my $str_chinese = '語言中心';
if ($m =~ /$str_chinese/) {
$m; ##if match, return the whole line.
}
}