Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Jun 272010
 

Wide character in print... warning in Perl

Answer:

Assume you have a simple script that print out UTF-8 characters in your script.

E.g.


#!/usr/bin/perl

my $foo = "Hello \x{4E2D} \x{570B}\n";   

print $foo;

When you run it, it will give out warnings...

Wide character in print at test.pl line 5.
Hello 中 國

To fix for the problem, add the line at the top of your program.

use encoding "utf-8";

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>