I found this sample script from How can I guess the encoding of a string in Perl?
#!C:\perl\bin
use utf8;
use Encode qw(encode PERLQQ XMLCREF);
my $string = 'This year I went to 北京 Perl workshop.';
#print encode('ascii', $string, PERLQQ);
# This year I went to \x{5317}\x{4eac} Perl workshop.
print encode('ascii', $string, XMLCREF); # This year I went to 北京 Perl workshop.
After having a test I found the encoded output result to be:
This year I went to \x{71fa9} Perl workshop.
This year I went to 񱾩 Perl workshop.
Looks like the result is different from the one author shows us above in the sample code.
I wonder how could I encode a character string and make its output in the numeric character reference format (&#xHHHH;
), for example when:
my $string = 'This year I went to 北京 Perl workshop.';
the encoded output would be:
This year I went to 北京 Perl workshop.