develooper Front page | perl.perl5.porters | Postings from May 2018

[perl #133177] [Unicode] Cannot print chr(0x00F6) properly

From:
Karl Williamson via RT
Date:
May 9, 2018 16:39
Subject:
[perl #133177] [Unicode] Cannot print chr(0x00F6) properly
Message ID:
rt-4.0.24-22017-1525883938-230.133177-15-0@perl.org
On Sat, 05 May 2018 01:14:34 -0700, wander4096@gmail.com wrote:
> * The Problem
> 
> $ perl -e 'print chr(0x00F6)'
> ?%                                                  $ perl -e 'print
> chr(0x4396)'
> Wide character in print at -e line 1.
> 䎖%
> 
> Where chr(0x00F6) should be ö and it is printed properly by Python or Perl
> 6 on my env so I infer that it is an issue about Perl.
> 
> * Version Info
> 
> $ perl -v
> 
> This is perl 5, version 26, subversion 2 (v5.26.2) built for
> darwin-thread-multi-2level
> 
> Copyright 1987-2018, Larry Wall
> 
> Perl may be copied only under the terms of either the Artistic License or
> the
> GNU General Public License, which may be found in the Perl 5 source kit.
> 
> Complete documentation for Perl, including FAQ lists, should be found on
> this system using "man perl" or "perldoc perl".  If you have access to the
> Internet, point your browser at http://www.perl.org/, the Perl Home Page.
> 
> - PS: Looking forward to your reply. At least let me know this e-mail has
> been received. I used `perlbug` program some days ago and got no reply.
> 
> Alex.

If you add the -C option, it works properly

perl -C -e 'print chr(0x00F6)'
ö

What I suspect is happening is that your terminal is set up for UTF-8 text.  Perl is printing the F6, but that is illegal UTF-8, and so your terminal doesn't handle it as one might expect.  Perl doesn't know what your terminal is set up for.  Specifying the -C tells it.  

With -C, perl converts the F6 to its UTF-8 representation before printing.

The reason anything above 0xFF does print correctly is that it can't possibly be represented by a single byte, and so Perl converts it to UTF-8, and your terminal is happy. But you get the wide character warning indicating that Perl expects your terminal to not be able to handle UTF-8.

I don't know why the other tools seem to work here.

Can you detail what happened when your perlbug failed? 
-- 
Karl Williamson

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



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