2 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/perl -w
use strict;
use Encode qw(decode);
use List::Util qw(max);
my $expected_octets = "äöü";
my $expected_charset = "iso-8859-1";
my $got_octets = "\204\224\201";
my @characters = split //, decode($expected_charset, $expected_octets);
my @res;
for my $encoding (Encode->encodings(":all")) {
eval {
my @got_characters = split //, decode($encoding, $got_octets);
my $max_length = max(scalar(@characters), scalar(@got_characters));
my $hits = 0;
for my $i (0 .. $max_length-1) {
no warnings 'uninitialized';
$hits++ if ($characters[$i] eq $got_characters[$i]);
}
push @res, { Quality => ($hits/$max_length)*100,
Encoding => $encoding,
};
};
}
print join("", map { sprintf "%-20s: %d%%\n", $_->{Encoding}, $_->{Quality} } sort { $b->{Quality} <=> $a->{Quality} } grep { $_->{Quality} > 0 } @res);
2 Einträge, 1 Seite |