Re: create a uft8 file
- From: chas.owens@xxxxxxxxx (Chas Owens)
- Date: Fri, 31 Aug 2007 15:07:21 -0400
On 8/31/07, Digger <digger@xxxxxxxxxxx> wrote:
Hello,snip
I want to create an utf8 file and write some content (like html codes) to it.
How to do it? thanks.
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
- References:
- create a uft8 file
- From: Digger
- create a uft8 file
- Prev by Date: Re: Big unicode problem with Perl 5.8.8 with MySQL 5.0 (i.e. Debian 4.0)
- Next by Date: type comparison in perl
- Previous by thread: create a uft8 file
- Next by thread: finding methods and attributes in a name space
- Index(es):
Relevant Pages
|
|