UTF-8 + HTML::Template + CGI::Fast

damien krotkine dams at gentoo.org
Fri Dec 4 11:25:22 GMT 2009


I don't see why "use utf8;" would be required, or helpful here. AFAIK (and
from perlunicode manpage), "use utf8;" is to be used to signify perl that
you use UTF8 encoded characters in the Perl source code. Which is probably
not the case.

If Andy happens to have latin1 encoded Perl script files (which is quite
comon), I bet "use utf8;" is not going to help, and is probably going to
confuse him when he try to, say, match a strange character with a regexp.

"As a compatibility measure, the "use utf8" pragma must be explicitly
included to enable recognition of UTF-8 in the Perl scripts themselves (in
string or regular expression literals, or in identifier names)
on ASCII-based machines".

dams

2009/12/4 Dave Hodgkinson <davehodg at gmail.com>

>
> On 4 Dec 2009, at 10:25, Andrew McGregor wrote:
>
> > Hello,
> >
> > I'm hoping someone can help me with a UTF-8 problem.
> >
> > If a user enters latin-1 into a (CGI::Fast) form and submits, and the
> > string is displayed (HTML::Template) as expected.
> >
> > If a user enters UTF-8 chars then the string displayed is corrupt, or
> > looks like it has been double encoded.
> >
> > If I remove CGI::Fast then there is no problem.
> >
> > If I die $string before hitting HTML::Template then the UTF-8 string
> > is displayed properly.
> >
> > I've patched HTML::Template to allow UTF-8 files.  I've tried passing
> > in a fh opened as UTF-8 (segfault).
> >
> > I read somewhere that Perl doesn't cope well concatenating latin-1 and
> > UTF-8 strings - could this be happening in HTML::Template?
> >
> > Or should I be posting somewhere else, HTML::Template list or CGI::Fast
> list?
> >
> > This is perl, v5.8.8 built for i386-linux-thread-multi
>
>
> Consistency is the key. If you know Latin-1 is coming in from the
> form, use Encode to convert it to UTF-8 and thus tell perl that's
> what it is.
>
> Oh, and "use utf8;" for good measure.
>
> Apparently, a string isn't just a stream of octets :)
>
> At least you don't have MySQL in the loop.
>
>
> --
> Dave Hodgkinson                                MSN: davehodg at hotmail.com
> Site: http://www.davehodgkinson.com                  UK: +44 7768 490620
> Blog: http://www.davehodgkinson.com/blog
> Photos: http://www.flickr.com/photos/davehodg
>
>
>
>
>
>
>
>
>
>


More information about the london.pm mailing list