Bug#409704: utf8 fun with $!, $@ etc

Dominic Hargreaves dom at earth.li
Sun Mar 31 23:30:19 UTC 2013


found 409704 5.14.2-20
thanks

On Sun, Feb 04, 2007 at 04:02:58PM -0500, Joey Hess wrote:
> joey at kodama:~>LANG=fr_FR.UTF-8 perl -e 'use open qw{:utf8 :std};open(foo) || print STDERR "error: $!\n";'
> error: Aucun fichier ou répertoire de ce type
>                          ^^
> This mojibake comes about because $! is a UTF-8 string in that locale, but it
> is not decoded into perl's internal utf8 representation.
> 
> It's possible to work around the problem with the encoding pragma, but
> not completely:
> 
> joey at kodama:~>LANG=fr_FR.UTF-8 perl -e 'use open qw{:utf8 :std}; use encoding 'utf8';open(foo) || print STDERR "error: $!\n";'    
> error: Aucun fichier ou répertoire de ce type
> 
> joey at kodama:~>LANG=fr_FR.UTF-8 perl -e 'use open qw{:utf8 :std}; use encoding 'utf8';open(foo) || print STDERR "error: ",$!,"\n";'
> error: Aucun fichier ou répertoire de ce type
> 
> The first example works because the encoding pragma converts the string
> to utf8 during concacenation, but the second example shows that this is
> not a solution because concacentation can't be relied on for all output.
> 
> The only solution if you want to use open qw{:utf8 :std} in a program
> seems to be manually using Encode::decode_utf8 on every instance of $!
> and $@ in the program. Which is exactly the kind of error-prone busywork
> that IO layers and perl's unicode model are supposed to avoid..

The French example doesn't work any more, becuase that error message
has been changed to one without accents, but this is still an issue
if we pick a suitable language:

$ LANG=ja_JP.UTF-8 perl -e 'use open qw{:utf8 :std};open(foo) || print STDERR "error: $!\n";'
error: ãã®ãããªãã¡ã¤ã«ããã£ã¬ã¯ããªã¯ããã¾ãã
$ LANG=ja_JP.UTF-8 perl -e 'use open qw{:utf8 :std}; use encoding 'utf8';open(foo) || print STDERR "error: $!\n";'
error: そのようなファイルやディレクトリはありません

I can't find this reported anywhere in the upstream RT, but I want to
check a bit more carefully before forwarding it, because it seems
like a fairly widespread problem so it may be that I've missed it.

Also happens with perl 5.17.10.

Dominic.

-- 
Dominic Hargreaves | http://www.larted.org.uk/~dom/
PGP key 5178E2A5 from the.earth.li (keyserver,web,email)




More information about the Perl-maintainers mailing list