UTF-8 handling in Perl for I/O (Wide character in say at)

If you handle UTF-8 I/O streams in Perl and if this is not explicitly activated either as argument of your Perl interpreter or within your Perl script, you can have this warning :

Wide character in say at

If you enable the pragma use diagnostics, more details will be provided for this warning :

Wide character in say at
(S utf8) Perl met a wide character (ordinal >255) when it wasn’t
expecting one. This warning is by default on for I/O (like print).

If this warning does come from I/O, the easiest
way to quiet it is simply to add the :utf8 layer, e.g.,
binmode STDOUT, ‘:utf8’. Another way to turn off the warning is
to add no warnings ‘utf8’; but that is often closer to
cheating. In general, you are supposed to explicitly mark the
filehandle with an encoding, see open and “binmode” in perlfunc.

If the warning comes from other than I/O, this diagnostic probably
indicates that incorrect results are being obtained. You should examine
your code to determine how a wide character is getting to an operation
that doesn’t handle them.

This StackOverflow answer provides a way to activate UTF-8 on I/O as as a command-line flag -CS : https://stackoverflow.com/questions/15210532/use-of-use-utf8-gives-me-wide-character-in-print

-CS enables UTF-8 on the Perl I/O on all the filehandles (STDIN, STDOUT and STDERR).

To enable this feature within your Perl script, use open “perl pragma to set default PerlIO layers for input and output” :

use open qw(:std :utf8);

More details :

Perl documentation : open perl pragma

Perl Unicode Cookbook : Make All I/O Default to UTF-8

Advertisements

Data::Printer Perl module on Debian Buster

To see what’s inside a variable or a Perl object, Data::Dumper is often used.
For inspecting objects, its features are limited.
Data::Printer helps you dump your Perl data structures in a complete, colored and human-friendly way.
This module is not part of the Perl core modules.
To install it on Debian Buster :

apt install libdata-printer-perl

Start using it. Its syntax is simple and pretty straightforward.
For objects, it provides public/private methods details that Data::Dumper does not.

More details on Metacpan for Data::Printer