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

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";

my $poem =
        "ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ\n" .
        "ᛋᚳᛖᚪᛚ᛫ᚦᛖᚪᚻ᛫ᛗᚪᚾᚾᚪ᛫ᚷᛖᚻᚹᛦᛚᚳ᛫ᛗᛁᚳᛚᚢᚾ᛫ᚻᛦᛏ᛫ᛞᚫᛚᚪᚾ\n" .
        "ᚷᛁᚠ᛫ᚻᛖ᛫ᚹᛁᛚᛖ᛫ᚠᚩᚱ᛫ᛞᚱᛁᚻᛏᚾᛖ᛫ᛞᚩᛗᛖᛋ᛫ᚻᛚᛇᛏᚪᚾ᛬\n";

print $fh $poem;

without saying anything special and it just works.  If you have HTML
entities that you want to translate into utf8 characters (or
vise-versa, there are modules on CPAN that can help you (such as
HTML::Entities*).

from perldoc perluniintro
       Starting from Perl 5.8.0, the use of "use utf8" is no longer necessary.
       In earlier releases the "utf8" pragma was used to declare that opera‐
       tions in the current block or file would be Unicode-aware.  This model
       was found to be wrong, or at least clumsy: the "Unicodeness" is now
       carried with the data, instead of being attached to the operations.
       Only one case remains where an explicit "use utf8" is needed: if your
       Perl script itself is encoded in UTF-8, you can use UTF-8 in your
       identifier names, and in string and regular expression literals, by
       saying "use utf8".  This is not the default because scripts with legacy
       8-bit data in them would break.  See utf8.

* http://search.cpan.org/~gaas/HTML-Parser-3.56/lib/HTML/Entities.pm

Reply via email to