I've been bitten by this a thousand times and though I generally manage
to solve the problem, I found no "general" solution. All I could come
up is a trial and error method. If $input is some string you need to
work on:
(1) (try) call utf8::decode($input) (or encode)
(2) $output = do stuff with $input
(3) (try) call utf8::encode($output) (or decode)
and send $output to browser.
Steps (1) and (3) are "trial and error". You need to try/test each
variant until it works without warning.
For example, I frequently need to parse a piece of HTML, do some
modifications to it and return the modified version to browser. With
HTML::TreeBuilder (excellent piece of work!) I do the following:
my $tree = HTML::TreeBuilder->new;
utf8::decode($html);
$tree->parse($html);
$tree->eof;
my $root = $tree->disembowel();
# now do stuff with $root and children
my $output = $root->as_HTML;
utf8::encode($output);
# safe to send $output to browser now, or to put it in DB.
I'd love to hear a better answer, of course. ("man perlunicode" won't do).
-Mihai
Andrew McFarland wrote:
> Hi,
>
> Sometimes when I run a TT script of mine I get the following warning:
>
> Wide character in print at /usr/lib/perl5/Template.pm line 168
>
> What is the best way to get rid of this? My instinct says to go
> through the source data and search for wide characters, but I have no
> idea how to go about this.
>
> Andrew
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates