perl-unicode

Re: Interpretation of non-UTF8 strings

2004-08-16 09:30:06
Marcin 'Qrczak' Kowalczyk <qrczak(_at_)knm(_dot_)org(_dot_)pl> writes:
W liście z pon, 16-08-2004, godz. 16:54 +0300, Jarkko Hietaniemi
napisał:

The encoding pragma partially works. It doesn't influence assumed
encoding of files opened without specifying the encoding, nor handling
of filenames, and it needs to be told about the encoding literally.
How to say it should be taken from the locale?

The 'use open ":locale"' does not work for you?

[qrczak ~]$ echo ąćę >1
[qrczak ~]$ perl -e 'use open ":locale"; open F, "1"; print <F>'
ąćę

Seems to work.

[qrczak ~]$ perl -Mencoding=latin2 -e 'use open ":locale"; open F, "1"; print 
<F>'
"\x{66a8a}" does not map to iso-8859-2 at -e line 1, <F> line 1.

Seems we may have a double encoding problem there,
open :locale says "please take characters from file in locales encoding
and convert them to unicode". 
While use encoding qw(latin2) says assume chars are latin2
(and they aren't any more as encoding layer has converted them for you.)

Hmm.


Also, 'use encoding' must still have the encoding specified literally,

Which makes a kind of sense to me.
'use encoding qw(...)' 
(mainly) sets meaning of literals in the script.
Presumably you know what encoding you are in when you write 
your script, but you don't know what locale user will be in when script
gets run.


<Prev in Thread] Current Thread [Next in Thread>