develooper Front page | perl.perl5.porters | Postings from April 2010

Effect of -C command line switch on `warn` and `die`

Thread Next
From:
Michael Ludwig
Date:
April 24, 2010 01:39
Subject:
Effect of -C command line switch on `warn` and `die`
Message ID:
0F9ABA01-7321-4413-B564-754FDAAECE54@xing.com
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 four 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 today 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 for print, but 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


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About