Fellow devoted!

I wrote a simple web script to add some (UTF-8 encoded) texts into database. Somehow is there a bug which i can't find. I simplified it to bones and it still does not work.

When i enter plain ascii, it is OK. When i enter Latin1 diacritics like "öä", they turn out like "��". When i try use somethin outside of Latin1, it turns to "Internal server error" and from log i see: "Cannot decode string with wide characters at /usr/lib/perl/5.10/Encode.pm line 162."

As far as i see, i have data properly encoded and headers define charset right way. I put test ( is_utf8() ) in script and it yells "1" to log. So where is the glitch here?

#!/usr/bin/perl use strict; use locale; use utf8; use open ':std' => ':encoding(UTF-8)'; use CGI qw(:all -utf8); my $q = new CGI; my %p = $q->Vars; warn utf8::is_utf8($p{text}); # says: 1 warn $p{text}; # shows uglified chars in log too print $q->header(-type=>"text/html", -charset=>"UTF-8"); print $q->start_html(-encoding=>"UTF-8"); print $q->pre( $p{text} ); print $q->p("some pretty UTF-8 formed characters: öäüõžš¢ð€¶"), $q->start_form, $q->textarea('text', '' , 10, 40), $q->br, $q->submit('view', 'view'), $q->end_form, $q->end_html;

TIA,

Nõnda, WK

In reply to Confusing UTF-8 bug in CGI-script by wanradt

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.