Determine language and charset simultaneously


my($al,$ac) = ($r->header_in("Accept-Language"),
               $r->header_in("Accept-Charset");
if (not defined $ac){
  my $protocol = $r->protocol || "";
  my($major,$minor) = $protocol =~ m|HTTP/(\d+)\.(\d+)|;
  $ac = "utf-8" if $major >= 1 && $minor >= 1;
}
my $hhh = HTTP::Headers->new("Accept-Language", $al
                             "Accept-Charset", $ac);
my $variants = [
['ja+utf-8',      1.0,undef,undef,'utf-8',      'ja',undef],
['ja+iso-2022-jp',0.1,undef,undef,'iso-2022-jp','ja',undef],
['de+utf-8',      1.0,undef,undef,'utf-8',      'de',undef],
['de+iso-8859-1', 1.0,undef,undef,'iso-8859-1', 'de',undef],
];

$pref = HTTP::Negotiate::choose($variants, $hhh);


Internationalization
O'Reilly Apache Conference, 24 August 1999
Andreas König (on CPAN: ANDK)
<andreas.koenig@anima.de>