UTF-8 output mode is not turned on by default, nor is it automatically set when scalars whose utf8 flag is set happen to be printed to the file handle.
(update: you should do binmode STDOUT, ":utf8"; as well, if you're going to print wide characters to STDOUT.)
Another update: (sorry -- I should have read the whole post, carefully, sooner) So you are printing utf8 data to an in-memory scalar-variable-as-file, and then you want to just print the contents of that scalar as if it were not an in-memory file (but just a utf8 string).
The problem there is that using the scalar as a file makes it impossible for perl to realize that it's really a utf8 string (the fact that you "opened" the file with ">:utf8" does not cause the variable's "utf8 flag" to be turned on).
So if you want perl to treat that variable as a utf8 string, you have to set the utf8 flag, and the supported way to do that is to use Encode::decode...
When the utf8 flag isn't set, but there are high-bit bytes in the string and the output file handle is set to utf8, perl will pretend that the string is actually Latin1, and "promote" it to utf8, which of course is a form of corruption in your case.use Encode; # ... treat $output2 as an output file, then: $output2 = decode( "utf8", $output2 ); # assuming that STDOUT is set to utf8 mode, you can now safely print "$output2\n";
In reply to Re: utf8 encoding and warnings woe
by graff
in thread utf8 encoding and warnings woe
by GrandFather
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |