Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hi all,
working on one web project I can see strange behaviour when I use $data = Encode::decode_utf8($data). This code does not set utf8 flag on for $data. Script is running under Apache2 with mod_perl and use CGI for params haldling.

I need to compare posted value with old one stored in database and update database only if posted different value. Looking to log i saw that fields with some characters are updated every time. After little debugging I found the reason - newly posted values does not have marked as utf8...

At the bedining of my script I call init function like this one

sub init { my $q = CGI->new; for my $param ($q->param) { if ($param =~ /^(.+)$/) { $Params::vars{$1} .= fix_utf($q->param($param)); } } $q->delete_all(); } sub fix_utf { my $par = shift; my $res = ''; # decode obtained value to utf8 string if needed $res = Encode::decode_utf8($par) if !Encode::is_utf8($par); print STDERR "value: '$par'\n" "\tflg1: \t", Encode::is_utf8($par) ? 1 : 0, "\n", "\tflg2: \t", Encode::is_utf8($res) ? 1 : 0, "\n"; # # set utf8 flag if previous operation failed # Encode::_utf8_on($res) if !Encode::is_utf8($res); # print STDERR "\tflg3: \t", Encode::is_utf8($res) ? 1 : 0, "\n"; return $res; }

As you can see I also try to set utf8 flag on by using Encode::_utf8_on call and even if this is uncommented I get sometimes following output

value: 'some note' flg1: 0 - original flg2: 0 - after decode_utf8() flg3: 0 - after _utf8_on()

There are also some warnings in apache log I don't underestand.

Use of uninitialized value in require at (eval 35) line 6, <FH> line 9 + (#2) [Fri Dec 5 16:23:17 2003] -e: Use of uninitialized value in require a +t (eval 35) line 6, <FH> line 9. [Fri Dec 5 16:23:17 2003] -e: Use of uninitialized value in require a +t (eval 35) line 6, <FH> line 9. Use of uninitialized value in require at /usr/lib/perl5/5.8.0/utf8_hea +vy.pl line 64, <FH> line 9 (#2) [Fri Dec 5 16:23:17 2003] -e: Use of uninitialized value in require a +t /usr/lib/perl5/5.8.0/utf8_heavy.pl line 64, <FH> line 9. [Fri Dec 5 16:23:17 2003] -e: Use of uninitialized value in require a +t /usr/lib/perl5/5.8.0/utf8_heavy.pl line 64, <FH> line 9. Use of uninitialized value in require at /usr/lib/perl5/5.8.0/utf8_hea +vy.pl line 78, <FH> line 9 (#2) [Fri Dec 5 16:23:17 2003] Exact.pl: Use of uninitialized value in req +uire at /usr/lib/perl5/5.8.0/utf8_heavy.pl line 78, <FH> line 9. [Fri Dec 5 16:23:17 2003] Exact.pl: Use of uninitialized value in req +uire at /usr/lib/perl5/5.8.0/utf8_heavy.pl line 78, <FH> line 9. Use of uninitialized value in do "file" at /usr/lib/perl5/5.8.0/utf8_h +eavy.pl line 137, <FH> line 9 (#2) [Fri Dec 5 16:23:17 2003] -e: Use of uninitialized value in do "file" + at /usr/lib/perl5/5.8.0/utf8_heavy.pl line 137, <FH> line 9. [Fri Dec 5 16:23:17 2003] -e: Use of uninitialized value in do "file" + at /usr/lib/perl5/5.8.0/utf8_heavy.pl line 137, <FH> line 9.

What's going wrong and how can I fix it?

Thanks ph0enix


In reply to Encode - can't set utf8 flag on + strange warnings in Apache log by ph0enix

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others examining the Monastery: (3)
    As of 2024-07-25 03:03 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?
      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.