CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Writing utf8 chars


New User

Feb 2, 2007, 1:02 PM

Post #1 of 2 (988 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):

farf("before my $x \n");

The problem is that, in the output file, the Ja chars are always corrupted:


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!


New User

Feb 5, 2007, 11:22 AM

Post #2 of 2 (978 views)
Re: [whitejm12] Writing utf8 chars [In reply to] Can't Post


include the following line at the start of your routine
use open ':utf8';

We had trouble in including extened Ascii chars in our scripts. After using the above it helps us

Also when you open files use
open (FILE, ">:utf8", "");



Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives