[Catalyst] write utf8 to STDOUT "wide character in print"

Jonathan Rockway jon at jrock.us
Sun Nov 19 01:39:47 GMT 2006


On Saturday 18 November 2006 16:51, apv wrote:
> I am getting "wide character in print" warnings to the terminal for
> tests and such still when all my utf8 is acting perfect in the
> browser (and even in MIME headers for email the app is sending, so
> I'm pretty sure I'm doing it all correctly).
>
> Since the engine is trying to be aware of the content (and the
> default headers are utf8), shouldn't it try to talk to the output the
> same way?

You're assuming that perl internally represents characters in utf8.  While 
your assumption is correct, it's best to explicitly convert perl characters 
to octets of your desired encoding.  The "wide character in print" warnings 
is perl's way of telling you that your code is going to break if the internal 
representation is changed.  (It would also break if someone set the binmode 
on stdout to the local locale's character encoding.)

If utf8 is your desired output encoding, utf8::encode($string) will convert 
perl's internal characters to utf8 octets. Catalyst::Plugin::Unicode will do 
this automatically, if you want.  (You'll also want to utf8::decode incoming 
octets, so that you can treat them like perl characters.  If you don't, 
something like m/./ will match one octet, not one character.)

-- 
package JAPH;use Catalyst qw/-Debug/;($;=JAPH)->config(name => do {
$,.=reverse qw[Jonathan tsu rehton lre rekca Rockway][$_].[split //,
";$;"]->[$_].q; ;for 1..4;$,=~s;^.;;;$,});$;->setup;



More information about the Catalyst mailing list