How to detect latin1 and UTF-8?
I am extracting strings from an XML file, and even though it should be pure UTF-8, it is not. My idea was to #!/usr/bin/perl use warnings; use strict; use Encode qw(decode encode); use Data::Dumper; my $x = "m\x{e6}gtig"; my $y = "m\x{c3}\x{a6}gtig"; my $a = encode('UTF-8', $x); my $b = encode('UTF-8', $y); print Dumper $x; print Dumper $y; print Dumper $a; print Dumper $b; if ($x eq $y) { print "1\n"; } if ($x eq $a) { print "2\n"; } if ($a eq $y) { print "3\n"; } if ($a eq $b) { print "4\n"; } if ($x eq $b) { print "5\n"; } if ($y eq $b) { print "6\n"; } outputs $VAR1 = 'm�gtig'; $VAR1 =