
whitejm12
New User
Feb 2, 2007, 1:02 PM
Post #1 of 2
(298 views)
|
|
Writing utf8 chars
|
Can't Post
|
|
Pre-newbie question (I didn't see an answer in the FAQs). ActivePerl 5.6.1 Part 1 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): my($x)=@_; farf("before my $x \n"); $x=~s/^(\s*)CLASS?\b/$1Clas日本ses/i; The problem is that, in the output file, the Ja chars are always corrupted: Clas譌・譛ャses I placed use utf8 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? Part 2 Here's how I save the file: my($filename, @contents)=@_; open (MYOUT, ">$filename"); print MYOUT @contents; close MYOUT; 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! John
|