use CGI qw(:standard);
%contents = map { $_ => get_data($_) } param;
%_GET = %contents;
sub get_data {
my $name = shift;
my @values = param($name);
return @values > 1 ? \@values : $values[0];
} On the HTML form, I use:On the form, or on the page as a whole? Either way, a charset declaration doesn't do anything to data coming in (from user to site). It just tells the browser how to render the HTML going in the other direction, from site to user.
<meta charset="UTF-8">
use CGI qw(:standard);
use Encode;
%contents = map { $_ => get_data($_) } param;
%_GET = %contents;
sub get_data {
my $name = shift;
my @values = encode("utf-8", param($name));
return @values > 1 ? \@values : $values[0];
}
to decode whatever the param isCan’t be done. (While investigating “repair text encoding” I fell into a rather interesting rabbit hole [hsivonen.fi]. Interesting to me, at least.) One can often tell whether material is in a multi-byte encoding--most likely though not necessarily UTF-8--or a one-byte encoding. But unless you're matching against a finite set of possible inputs, it would be impossible for a computer of ordinary intelligence to tell which one-byte encoding.