in reply to Issue of formatting columns of data

You need to
  1. Save the source file as UTF-8.
  2. Tell Perl that it is UTF-8.
  3. Tell Perl to encode the output as UTF-8.
#! /usr/bin/perl use warnings; use strict; use utf8; use open IO => ':encoding(UTF-8)', ':std'; print sprintf ("%-6s", "°C"). "|\n"; print sprintf ("%-6s", "Deg C")."|\n";
Output (in a UTF-8 terminal):
°C    |
Deg C |

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Issue of formatting columns of data
by Timka (Acolyte) on Sep 26, 2024 at 03:44 UTC
    Any of these would work:

    • binmode STDOUT, "encoding(UTF-8)"
    • binmode STDOUT, ":utf8"
    • use open qw(:std :utf8);
    • perl -C your_script
      • *please* do NOT promote binmode ..., ":utf8";, as that is unsafe
      • The :encoding(utf-8)" is missing a :
      • perl -C is for output only (I'd use -COE for clarity), not for the source code. UTF-8 in source code requires perl -COE -Mutf8 -wE'say "°C"'

      Enjoy, Have FUN! H.Merijn