Skip to content

Instantly share code, notes, and snippets.

@hamakn
Last active December 15, 2015 16:29
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 hamakn/5289545 to your computer and use it in GitHub Desktop.
Save hamakn/5289545 to your computer and use it in GitHub Desktop.
prelの内部文字列がわかってなくて死んだ
use 5.016;
use utf8;
use Encode;
use Encode::Guess qw/utf8 euc-jp shiftjis/;
my $str = 'あああ';
say guess_encoding($str)->name;
# => utf8
say $str eq encode_utf8($str);
# => ''
say $str eq encode_utf8(encode_utf8($str));
# => ''
say encode_utf8($str) eq encode_utf8(encode_utf8($str));
# => ''
# coding: utf-8
# ↑ (ruby2.0以降であればdefault encodingはutf8なので不要)
str = "あああ"
p str.encoding
# => #<Encoding:UTF-8>
p str == str.encode("UTF-8")
# => true
p str == str.encode("UTF-8").encode("UTF-8")
# => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment