The server had already added the UTF-8 content type in the HTTP headers
Could you please elaborate which server you are using, and how you configure it to modify the content type of a CGI script? You could also verify in your browser which encoding it uses for your text/plain response.
I also had a look at the source of CGI::Simple and found out:
- The module will decode parameters for you only if you set the global variable $CGI::Simple::PARAM_UTF8 to a true value. That's sort of difficult to guess, since it isn't documented. Of course, you can decode yourself, but it looks like you didn't.
- The module will add ; charset=utf-8 to the content type header only if you print it as print $q->header(-type => 'text/plain');, but not if you just print "Content-type: text/plain\n\n";.
So, the following
just works for me:
use strict;
use warnings;
use CGI::Simple;
$CGI::Simple::PARAM_UTF8 = 1;
my $q = CGI::Simple->new();
$q->charset('utf-8');
binmode STDOUT,':encoding(UTF-8)';
print $q->header(-type => 'text/plain');
print $q->param('text'),"\n";
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.