Feb 2, 2007, 1:02 PM
Post #1 of 2
Pre-newbie question (I didn't see an answer in the FAQs).
Writing utf8 chars
I need to have my script (actually, it's somebody else's, and I've inherited it) preserve and write out Japanese chars to a .txt file. Note that I'm using the Ja chars themselves, not a &#xxxxx; representation of them.
I search for instances of "Class" in input files and replace them with the Ja translation of "Class" (pseudo-translated here):
farf("before my $x \n");
The problem is that, in the output file, the Ja chars are always corrupted:
at the top of the script file, but I think I need to specify that $1Clas日本ses/i is to be treated as UTF-8 and not flattened. How do I do this? At each $x= line?
Here's how I save the file:
open (MYOUT, ">$filename");
print MYOUT @contents;
When I save the file, I think I need to specify that it's going to be utf-8 encoded. I've tried
open(OUTFILE, ">:utf8", $MYOUT);
to no avail.
I looked through perldoc perluniintro or perldoc unicode, and the answer may be there, but I can't figure it out.
Thanks for any help!