Last active
December 15, 2015 23:49
-
-
Save hakobe/5343384 to your computer and use it in GitHub Desktop.
PerlのUTF-8フラグなんどやってもむずい
This file contains hidden or 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
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 | |
### | |
# 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