perlquestion
ph0enix
<p>Hi all,<br>
working on one web project I can see strange behaviour when I use <code>$data = Encode::decode_utf8($data)</code>. This code does not set utf8 flag on for $data. Script is running under Apache2 with mod_perl and use CGI for params haldling.</p>
<p>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...</p>
<p>At the bedining of my script I call init function like this one</p>
<code>
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;
}
</code>
<p>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</p>
<code>value: 'some note'
flg1: 0 - original
flg2: 0 - after decode_utf8()
flg3: 0 - after _utf8_on()</code>
<p>There are also some warnings in apache log I don't underestand.</p>
<code>
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 at (eval 35) line 6, <FH> line 9.
[Fri Dec 5 16:23:17 2003] -e: Use of uninitialized value in require at (eval 35) line 6, <FH> line 9.
Use of uninitialized value in require at /usr/lib/perl5/5.8.0/utf8_heavy.pl
line 64, <FH> line 9 (#2)
[Fri Dec 5 16:23:17 2003] -e: Use of uninitialized value in require at /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 at /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_heavy.pl
line 78, <FH> line 9 (#2)
[Fri Dec 5 16:23:17 2003] Exact.pl: Use of uninitialized value in require 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 require 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_heavy.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.
</code>
<p>What's going wrong and how can I fix it?</p>
<p>Thanks ph0enix</p>