I'd like to take some strings encoded in big5, convert them to utf-8,
and send them to the browser. The following script runs but doesn't
convert the strings correctly. The cgi is run by Apache on Redhat 7.1.
Perl is 5.6.0. Have I garbled the syntax for Unicode::Map and
Unicode::String?
Thanks,
Michael Fahey
#!/usr/bin/perl -w
#uni.pl
use CGI;
use Unicode::Map;
use Unicode::String qw(utf8 latin1 utf16);
my $Map = new Unicode::Map("BIG5");
my $cgi = new CGI;
$cgi->charset('utf-8');
print $cgi->header();
print $cgi->start_html();
my $data_file = '../data/uni.txt'; #see below for contents of uni.txt
open (IN, $data_file) or die "Couldn't open $data_file: $!\n";
#print some test unicode characters
print "\x{263A}", "","\x{263B}", "",
"\x{2630B}", "", "\x{7C70}", "";
while (){
chomp;
print "This is the raw string: $_", "";
my $utf16 = $Map ->to_unicode ($_);
print $utf16, "";
my $u = utf8($utf16);
print $u->utf8;
print "";
}
print $cgi->end_html();
##uni.txt###
uni.txt contains the characters for 'big', 'middle', and 'small' in
following three lines:
¤j
¤¤
¤p