Hello,

I am have a small problem with Tempaltes and displaying UTF8 characters correctly. The data is stored in a SQLite database and a query with the code below displays the correct UTF8 characters. However, when I send the results to Template I get strange malformed characters.

#!/usr/bin/perl use strict; use DBI; use Data::Dumper; my $wah = wah(); print @$wah; sub wah { my $dbh = new_dbh(); my @results; my $sth = $dbh->prepare("select s.show_name,sr.overview,sr.banner from + shows s,series sr where s.seriesid=sr.seriesid;"); $sth->execute(); while (my @rows = $sth->fetchrow_array() ) { push @results,@rows, } return \@results; } sub new_dbh { my $dbh = DBI->connect("dbi:SQLite:dbname=shows.db","","", {RaiseE +rror => 1, sqlite_unicode => 1}) or die "$DBI::errstr"; return $dbh; }
This returns the data, at the console, correctly and shows displays the characters correctly. However, if I send $wah to tempaltes to be dereferenced the display looks like:
Madison Avenue’s “Golden Ageâ€
Instead of this:
Madison Avenue’s “Golden Age”

Does anyone have any ideas what is going wrong? The data is being stored correctly in SQLite as a query from SQLite console shows the data correctly. Data::Dumper shows the characters correctly too, it's only when I send it to templates if fails over. I have tried my $template = Template->new({ ENCODING => 'utf8' }); but I am not sure if this works for Template at all.

UPDATE: OK, adding <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> to my header seems to have sorted this problem!
Nothing to see here, move along!!


In reply to Perl Template UTF8 by packetstormer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.