Please let me know where I'm going wrong.
You seem to have forgotten to give us something from which we could identify something wrong.
My first test would be to use Devel::Peek's Dump to check if I get what I need from Excel. Please provide the Dump of a variable that should contain Chinese chars.
| [reply] [d/l] |
Are you using strict? Did you enable warnings? Did you tell perl how to write Unicode characters to the text file? Does your text file viewer know how (i.e. in which encoding) perl wrote the unicode characters to the file? What "excel convertor code from CPAN" did you use? (Tell us the URL!) And by the way: Show us the code, wrapped in CODE-tags.
Alexander
--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
| [reply] |
Without any code to review, I would assume that the chinese characters are in UCS2 (UCS2-2BE) in excel and you're treating them like UTF-8 (or yikes ISO-8859-1) when outputting. Can you post *just* those snippets of the code that read the excel cell values?
| [reply] |
use Encode;
use Encode qw(encode decode);
binmode STDOUT, ':utf8';
print "Content-type: text/html; charset=utf-8\n\n";
open SOURCE, '<:encoding(utf8)',$sourcefile
or die "Cannot open source! $!\n";
open (TARGET, ">:encoding(utf8)", "$targetfile")
or die "Cannot open target file! $!\n";
print TARGET <<HTML;
<html lang="utf8">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf8">
...
<form name="myform" method="POST" accept-encoding="UTF-8" accept-chars
+et="utf-8" action="$thisprogram">
...
HTML
foreach $line (@source) {
$line = decode("utf-8", $line);
Note that you may not need to do all of these at once. For example, if you already read the file in as UTF8, there is no need to decode each line of the file as UTF8 again. However, redundancy should have no side effects other than adding a little more bulk to your code.
Blessings,
~ Polyglot ~ | [reply] [d/l] |