29 Apr 2010, 15:16

Perl: Wide character in print

Share

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”;