Hello Allen,

You say this:
  - "I have set character set to gb2312,"
  - "the encoding character set was set to gb2312"

But in your cgi code, I don't see any of these:
  - use Encode;
  - decode(...
  - encode(...
  - open FH ">:encoding(...
  - use open ':encoding(...

So it looks like you aren't telling perl which encoding to use.

I'm not an encoding expert by any stretch, but I think that in the absence
of your telling perl which encoding to use, it is falling back on UTF-8 (but
I'd expect you to see 'wide character' warnings, so maybe I'm wrong).
This may be why it looks okay when you set your browser to UTF-8.

How to fix?  As I said, I'm no expert.  If I were you, I'd start reading here:
http://perldoc.perl.org/perlunitut.html and follow all the links until it starts
to make sense (I'm currently in the process of doing that--again--myself).

Hope that helps (hope I'm at least partly correct),

-- Brad


On Fri, Mar 14, 2008 at 5:06 AM, Allen Zhang <actanzhang@gmail.com> wrote:
Hi all,

    My cgi script using Html::Template having some error display Chinese Character.
    I have set character set to gb2312, and the encoding character set was set to gb2312 too.
    But in  that case, the "" wasn't displayed as expected.
    However, I found that if I change the encoding character set of my browser to utf8, it displays perfectly.
    Why ?
    Most browsers in China were set to gb2312 encoding, I don't want users to manually change their
    default setting to view my page.
    What can I do?
    Thanks!!  


cgi code:
##################################################
#!/usr/bin/perl -w

use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);
use HTML::Template;

my $template = HTML::Template->new(filename => 'title.tpl.php');
my $title = '';
$template->param('title' => $title);
print header(-charset=>"gb2312");

print $template->output;

template code:
##################################################
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="description" content="">
<meta name="keywords" content="">
<title><TMPL_VAR NAME=title></title>
</head>
<body>
<TMPL_VAR NAME=title>
<br>
Hello!
<br>
Hard code
</BODY>
</HTML>



Allen Zhang