Created
May 31, 2012 03:25
-
-
Save prufrock/2840767 to your computer and use it in GitHub Desktop.
playing around with character encoding in perl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use utf8; | |
use Encode; | |
binmode STDOUT, ":encoding(UTF-8)"; | |
$string = "カタカナ, 片仮名"; | |
print "Internal Format: " . $string . "\n"; | |
$octets = encode("utf8", $string); | |
print "Encoded as UTF-8: " . $octets . "\n"; | |
print "Encoded as UTF-8(Unpacked as Hex): " . unpack("H*",$octets) . "\n"; | |
open my $out, ">", "utf8text.txt" or die "Couldn't open file"; | |
print $out $octets; | |
$octets = decode("utf8", $octets); | |
print "Decoded as UTF-8 to the internal format: " . $octets . "\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
カタカナ, 片仮名 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment