#!/usr/local/bin/perl use Encode qw(decode _utf8_off); open(my $fh_8bit, ">", "utf8.txt") or die "open utf8.txt: $^E"; open(my $fh_utf8, ">", "utf8.utf") or die "open utf8.utf: $^E"; # byte order mark für UTF-8 print $fh_utf8 "\xef\xbb\xbf"; for my $num (128 .. 255) { my $chr_8bit = chr($num); # von 8-Bit Zeichensatz (z.B. Windows CP1252) nach UTF-8 übersetzen my $chr_utf8 = decode("cp1252", $chr_8bit); # wir wollen die raw octets auslesen my $utf_octets = $chr_utf8; _utf8_off($utf_octets); my $raw_hex = ""; for my $byte (split(//, $utf_octets)) { $raw_hex .= sprintf("%02x", ord($byte)); } printf $fh_8bit ("Zeichen \\x%02x (%s) = UTF-8 \\x%s\n", $num, $chr_8bit, $raw_hex); printf $fh_utf8 ("UTF-8 \\x%-6s = Zeichen (%s) Octets %d Chars %d\n", $raw_hex, $utf_octets, length($utf_octets), length($chr_utf8)); }