Quantcast
Viewing all articles
Browse latest Browse all 8

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

Image may be NSFW.
Clik here to view.
flattr this!


Viewing all articles
Browse latest Browse all 8

Trending Articles