Hi Troy,
here is a untested example. Copy it to your cgi-bin/troy.pl. Without parameters it presenrs the submit form otherwise it shows the data everytime in utf8.
The error in your script is that you confuse utf8 and unicode somewhere.
Also the meta tags looks unnecessarily to me.
PS: Consider to add readmore tags around your code on pm.
#!/usr/bin/perl
use strict;
use Encode;
use CGI;
$|++;
my $c = CGI->new;
binmode( STDOUT, ":utf8" );
unless ( () = $c->param ) {
print $c->header( -charset => 'utf-8' ),
$c->start_html('Character conversion test'), qq{
<form action="/cgi-bin/troy.pl" method="post" enctype="multipart/f
+orm-data">
<input type="hidden" name="enc_sniffer" value="\x{df}\x{20ac}">
<textarea name="textInput" rows="25" cols="72"></textarea><p>
<input type="submit">
</form>}, $c->end_html;
exit;
}
else {
my $enc;
my $hidden = $c->param('enc_sniffer');
{
use bytes;
$enc =
( $hidden eq "\xc3\x9f\xe2\x82\xac" ) ? 'utf8'
: ( $hidden eq "\xdf\x80" ) ? 'cp1252'
: 'iso-8859-1';
}
# decode all param fields here
my $qtext = decode( $enc, $c->param('textInput') );
print $c->header( -charset => 'utf-8' ), $c->start_html("Encoding is
+ $enc"),
$enc, " ", $qtext, $c->end_html;
}
|