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}", "<br>","\x{263B}", "<br>",
    "\x{2630B}", "<br>", "\x{7C70}", "<br>";
while (<IN>){
    chomp;
    print "This is the raw string: $_", "<br>";
    my $utf16 = $Map ->to_unicode ($_);
    print $utf16, "<br>";
    my $u = utf8($utf16);
    print $u->utf8;
    print "<br>";
    

}
print $cgi->end_html();


######uni.txt###################
uni.txt contains the characters for 'big', 'middle', and 'small' in
following three lines:

¤j
¤¤
¤p

Reply via email to