Perl: Wide character in print

Wanna get rid of these annoying “Wide character in print” warning perl gives you sometimes when dealing with unicode/UTF-8?

Use

binmode(STDOUT, ":utf8");

on STDOUT or the appropriate filehandle, and perl will treat it as UTF-8 capable.

You could also use the “-CSDA” option to tell perl that.

Before:

#!/usr/bin/perl -w
use charnames ':full';
print "\N{GREEK CAPITAL LETTER DELTA}\n";

Gives:

./wide_char.pl
Wide character in print at ./wide_char.pl line 9.
Δ

After:

#!/usr/bin/perl -w
use charnames ':full';
binmode(STDOUT, ":utf8");
print "\N{GREEK CAPITAL LETTER DELTA}\n";

3 Responses to “Perl: Wide character in print”

  1. AB writes:

    Thanks! Worked perfectly.

  2. peterb writes:

    I think you should change the line from “get rid of” to “handle”. Honestly, this is the first solution I found that doesn’t just stop the warnings from showing up.

  3. Li writes:

    use open qw/:std :utf8/;

    I found this at the very start of the file to be more useful in my solution.