Skip to content

Instantly share code, notes, and snippets.

@hakobe
Last active December 15, 2015 23:49
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 hakobe/5343384 to your computer and use it in GitHub Desktop.
Save hakobe/5343384 to your computer and use it in GitHub Desktop.
PerlのUTF-8フラグなんどやってもむずい
use strict;
use warnings;
use Encode;
use Devel::Peek;
###
my $msg = decode_utf8('a') . ' あ'; # 'こんにちは'の部分は文字列連結時にLatin1としてdecodeされる
print STDERR $msg; # 表示がばけない
warn $msg; # 表示がばける
Dump($msg);
#SV = PV(0x7facb2806fe0) at 0x7facb282da50
# REFCNT = 1
# FLAGS = (PADBUSY,PADMY,POK,pPOK,UTF8)
# PV = 0x7facb2437dc0 "a \303\243\302\201\302\202"\0 [UTF8 "a \x{e3}\x{81}\x{82}"]
# CUR = 8
# LEN = 16
###
my $msg2 = decode_utf8('あ') . ' あ'; # 'こんにちは'の部分は文字列連結時にLatin1としてdecodeされる
print STDERR $msg2; # 表示がばける
warn $msg2; # 表示がばける
Dump($msg2);
#SV = PV(0x7facb284a578) at 0x7facb282da10
# REFCNT = 1
# FLAGS = (PADBUSY,PADMY,POK,pPOK,UTF8)
# PV = 0x7facb246b780 "\343\201\202 \303\243\302\201\302\202"\0 [UTF8 "\x{3042} \x{e3}\x{81}\x{82}"]
# CUR = 10
# LEN = 16
###
# print
# Unicodde文字列を表示しようとする ( PV の [UTF8... となっている部分 )
# ただし8bit表現可能な文字しか含まれていない場合はそのまま表示する???
# warn
# 文字列の内部表現を表示しようとする ( PV の [UTF8... よりも前の部分 )
# なんかよくわからない...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment