Hi Guys,
I need to match some chinese character in a utf8 encoded html , and I wrote some test code as below :
#! /usr/bin/perl
use strict;
use LWP::UserAgent;
use Encode;
my $ua = new LWP::UserAgent;
my $request = HTTP::Request->new('GET');
my $url = 'http://www.boc.cn/sourcedb/whpj/';
$request->url($url);
my $res = $ua->request($request) ;
my $str_chinese = encode("utf8" ,"英磅" ) ;
# my $str_chinese = "英磅" ;
my $str_english = "English" ;
#my $html = decode("utf8" , $res->content) ;
my $html = $res->content ;
if ( $html =~ /$str_chinese/ ) {
print "chinese word matched" ;
}else {
print "chinese word unmatched\n" ;
}
if ( $html =~ /$str_english/i ) {
print "english word matched\n" ;
}else {
print "english word unmatched\n" ;
}
The output shows that the the script fail to match the existing chinese characters embeded in the html. could you give me some hint on how to solve my problem ?