develooper Front page | perl.perl5.porters | Postings from September 2014

[perl #114334] Re-encoding gives unhelpful error message

From:
James E Keenan via RT
Date:
September 22, 2014 23:31
Subject:
[perl #114334] Re-encoding gives unhelpful error message
Message ID:
rt-4.0.18-22890-1411428694-1097.114334-15-0@perl.org
On Mon Jul 30 15:26:17 2012, dmcbride@cpan.org wrote:
> 
> This is a bug report for perl from dmcbride@cpan.org,
> generated with the help of perlbug 1.39 running under perl 5.12.4.
> 
> 
> -----------------------------------------------------------------
> [Please describe your issue here]
> 
> This is related to #113982, but not actually the same issue.
> 
> Because of the clobbering of PerlIO layers, I inserted some code to
> ensure
> that STDOUT and STDERR always have the correct encoding.  However,
> this
> code was being run even when the layers had not been clobbered.  This
> would
> result in double-encoding, and then I'd get an error message that was
> less
> than useful.
> 
> I would suggest, in increasing order of preference, one of:
> 
> a) Documentation for :raw indicating it is recommended for undoing all
> other encodings (or, better, some other way of popping out any
> encoding
> layer(s)), or
> 
> b) An error message when an encoding layer is added on top of another
> encoding layer, or
> 
> b) Clobbering (such as with :raw) old encodings when adding a new
> encoding layer.
> 
> Code:
> 
> #! /usr/bin/perl
> 
> use 5.10.1;
> 
> $text = "\x{65E0}\x{6CD5}\x{542F}\x{52A8}";
> 
> binmode STDOUT, ':encoding(eucCN)';
> binmode STDOUT, ':encoding(eucCN)';
> 
> say "== $_" for PerlIO::get_layers(STDOUT);
> 
> say $text;
> 
> __END__
> 
> I'm suggesting that this should produce the same output whether there
> is
> one or both of those binmode statements.  Note that if I change the
> second binmode to include :raw before :encoding, I get the desired
> output
> (see option (a) above).
> 
> (The Perl I'm using this on is 5.10.1, which is not the same as my
> local
> system perl, but this also happens on 5.16.0.)
> 

Reviewing this older ticket this evening, I had occasion to run the OP's program on perl 5.20.1.  Here's what I got?

#####
$ cat 114334-raw.pl 
use strict;
use warnings;
use feature 'say';

my $text = "\x{65E0}\x{6CD5}\x{542F}\x{52A8}";

binmode STDOUT, ':encoding(eucCN)';
binmode STDOUT, ':encoding(eucCN)';

say "== $_" for PerlIO::get_layers(STDOUT);

say $text;

$ perl 114334-raw.pl 
== unix
== perlio
== encoding(euc-cn)
== utf8
== encoding(euc-cn)
== utf8
"\x{fffd}" does not map to euc-cn at 114334-raw.pl line 12.
"\x{07b7}" does not map to euc-cn at 114334-raw.pl line 12.
"\x{fffd}" does not map to euc-cn at 114334-raw.pl line 12.
"\x{fffd}" does not map to euc-cn at 114334-raw.pl line 12.
"\x{fffd}" does not map to euc-cn at 114334-raw.pl line 12.
\x{fffd}\x{07b7}\x{fffd}\x{fffd}\x{fffd}
#####

Can anyone assess the significance of this output in relation to the OP's feature request?

Thank you very much.

-- 
James E Keenan (jkeenan@cpan.org)

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=114334



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