「语言中心」などの中国語の単語と一連の Web ファイル (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.
}
}