Consider the following script, the source of which is encoded in UTF-8: use utf8; use open qw/:utf8 :std/; my $str = "Käse\n"; print STDOUT $str; print STDERR $str; warn $str; die $str;
On a UTF-8 terminal, this prints Käse three times. So far, so good. Now remove the open pragma and execute the script using the -C switch, which is documented as follows in perlrun as seen at http://perldoc.perl.org/perlrun.html: ----8<---- -C [number/list] The -C flag controls some of the Perl Unicode features. As of 5.8.1, the -C can be followed either by a number or a list of option letters. The letters, their numeric values, and effects are as follows; listing the letters is equal to summing the numbers. • I 1 STDIN is assumed to be in UTF-8 • O 2 STDOUT will be in UTF-8 • E 4 STDERR will be in UTF-8 • S 7 I + O + E ----8<---- So -C7 or -CS should switch all channels to UTF-8. And they do, but only for print, not for warn and die, which seem to remain unaffected by -C. I've seen this behaviour for perl 5.8.9 and 5.10.1 for Darwin (Mac), as well as 5.8.7 and 5.8.9 for Linux. Don't know if this is a bug or a feature in Perl, or if the Perldoc for the -C switch should be updated to reflect the actual behaviour, which seems to be: • E 4 STDERR will be in UTF-8, but `die` and `warn` remain unaffected -- Michael.Ludwig (#) XING.com