Re: :encoding() layer modifies read-only scalars

[email protected] (Nick Ing-Simmons)
Newsgroups perl.unicode
Message-ID <[email protected]>
Bjoern Hoehrmann <[email protected]> writes:
>* Bjoern Hoehrmann wrote:
>>  Enocde 2.08, PerlIO::scalar 0.02, ActivePerl 5.8.2, 
>>
>>  #!perl -w
>>  use strict;
>>  use warnings;
>>  use Encode;
>>  
>>  my $string = encode(UTF16 => "");
>>  
>>  for (qw/UTF-8 UTF-16LE UTF-16BE UTF-32LE UTF-32BE/)
>>  {
>>    my $backup = $string;
>>    open F, "<:encoding($_)", \$backup;
>>    my $char;
>>    read F, $char, 1, 0;
>>    close F;
>>  
>>    die unless $backup eq $string;
>>  }

There are no "readonly scalars" there.

>>  
>>Gives
>>
>>  utf8 "\xFE" does not map to Unicode at ... line 13.
>>  utf8 "\xFF" does not map to Unicode at ... line 13.
>>  Unicode character 0xfffe is illegal at ... line 13.
>>  Died at ... line 16.
>
>Perl ActivePerl 5.8.4 and the same PerlIO::scalar/Encode the result is
>
>  utf8 "\xFE" does not map to Unicode at 1.pl line 13.
>  Unicode character 0xfffe is illegal at 1.pl line 13.
>  Died at 1.pl line 16.
>
>Which is still not what I would expect...

It seems UTF-16LE encoding does not work right with PerlIO::scalar
It is not clear which is at fault.

Personally, I would be more motivated to fix whichever is at fault 
if you explain why you are trying to read one character from 
a stream with no characters in it (except a BOM).
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.