----- original Nachricht -------- Betreff: Re: create a uft8 file Gesendet: Fr 31 Aug 2007 21:08:08 CEST Von: "Chas Owens"<[EMAIL PROTECTED]>
> 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; > Why not open $fh with ':utf8'? open my $fh, ">:utf8", "outfile" or die ...; otherwise you may got the warning: Wide character in print from perldoc perluniintro: Unicode I/O Normally, writing out Unicode data print FH $some_string_with_unicode, "n"; produces raw bytes that Perl happens to use to internally encode the Unicode string. Perl's internal encoding depends on the system as well as what characters happen to be in the string at the time. If any of the characters are at code points 0x100 or above, you will get a warning. To ensure that the output is explicitly rendered in the encoding you desire--and to avoid the warning--open the stream with the desired encoding. Some examples: open FH, ">:utf8", "file"; open FH, ">:encoding(ucs2)", "file"; open FH, ">:encoding(UTF-8)", "file"; open FH, ">:encoding(shift_jis)", "file"; and on already open streams, use "binmode()": binmode(STDOUT, ":utf8"); binmode(STDOUT, ":encoding(ucs2)"); binmode(STDOUT, ":encoding(UTF-8)"); binmode(STDOUT, ":encoding(shift_jis)"); "Jetzt Handykosten senken mit klarmobil - 14 Ct./Min.! Hier klicken" http://produkte.shopping.freenet.de/handy_voip_isdn/klarmobil/index.html?pid=730025 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/