Digger wrote:
Chas Owens wrote:
On 8/31/07, Digger <[EMAIL PROTECTED]> wrote:
I want to create an utf8 file and write some content (like html codes) to it. How to do it?

Modern Perl handles utf8 natively.  You can do things like:

#!/usr/bin/perl

use strict;
use warnings;

open my $fh, ">", "outfile"
        or die "Could not open outfile for writing:$!\n";

Does this mean I need to convert the string to utf8 at first then print it to $fh?

Yes, if your content was written with some other encoding.

Is there a way that I don't need to convert the string by hand?I mean when printing,perl convert it to utf8 automaticly.

You can let Perl convert it before printing. Example:

    use Encode;
    Encode::from_to( $string, 'iso-8859-1', 'utf8' );

See "perldoc Encode".

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to