in reply to Help for "Cannot decode string with wide characters..." and CGI.pm

upgrade Encode CGI Encoding   cpanp -i Encode CGI Encoding

  • Comment on Re: Help for "Cannot decode string with wide characters..." and CGI.pm
  • Download Code

Replies are listed 'Best First'.
Re^2: Help for "Cannot decode string with wide characters..." and CGI.pm
by PerlBroker (Acolyte) on Apr 08, 2012 at 12:20 UTC
    After upgrade of Encode and CGI, it started working, at least there is no error. But now I get these characters in messages: ��
      Maybe something like this:
      #!/usr/bin/perl -l BEGIN { $| = 1;} use strict; use warnings; use utf8; use Encode; use CGI qw/:standard -utf8/; use CGI::Carp qw/fatalsToBrowser set_message/; $CGI::PARAM_UTF8 = 1; BEGIN { sub handle_errors { my $msg = shift; print "<h1>There's a problem</h1>"; print "<p>Cannot decode string: $msg</p>"; } set_message(\&handle_errors); } my $q = CGI->new; binmode STDOUT, ":encoding(UTF-8)"; my $referer_url = "@{[ $q->url ];}"; print $referer_url;
        I get it, that strings shall not be double decoded. I got it to work without errors, but I do not get the UTF-8 displayed.
        print $q->header(-charset => 'utf-8'); my $val = $q->param('key'); print utf8::is_utf8($val); exit;
        This test gives me 1, which means, the value is UTF-8. But the value is not correctly displayed, just strange signs. Do you know what to do?
        Thank you for this tip, I will use that to get better error messages. But yet it does not give me the string in UTF-8 and it shows the error again: The code is just as yours, with this in the end:
        print $q->header; print decode utf8 => $q->param('key');
        The "decode utf8" is not needed in my opinion, as the input is already UTF-8, and same error "wide character" is shown on above. But without "decode utf8 =>" I get no errors, but I get this characters: �� -- occurrence is strange, as the script just worked fine with Unicode. Any clues?