Skip to content

Instantly share code, notes, and snippets.

@prufrock
Created May 31, 2012 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prufrock/2840767 to your computer and use it in GitHub Desktop.
Save prufrock/2840767 to your computer and use it in GitHub Desktop.
playing around with character encoding in perl
#!/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";
カタカナ, 片仮名
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment