Last active
August 29, 2015 14:04
-
-
Save monmon/242332623d06bdc1078d to your computer and use it in GitHub Desktop.
Perl v5.8.5で内部文字列をsubstrするとbugる
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
#!perl | |
use strict; | |
use warnings; | |
use utf8; | |
use Devel::Peek; | |
my $str = '{"a":"b","c":"あ"}'; | |
Dump $str; | |
print <<EOS; | |
===================================== | |
@{[ substr($str, 2, 1) ]} | |
===================================== | |
EOS | |
my $sub = substr($str, 2); | |
Dump $str; | |
print <<EOS; | |
===================================== | |
@{[ substr($str, 2, 1) ]} | |
===================================== | |
EOS |
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
% perl -v | |
This is perl, v5.8.5 built for x86_64-linux-thread-multi | |
Copyright 1987-2004, Larry Wall | |
Perl may be copied only under the terms of either the Artistic License or the | |
GNU General Public License, which may be found in the Perl 5 source kit. | |
Complete documentation for Perl, including FAQ lists, should be found on | |
this system using `man perl' or `perldoc perl'. If you have access to the | |
Internet, point your browser at http://www.perl.com/, the Perl Home Page. | |
% perl ~/substr_bug.pl | |
SV = PV(0x506550) at 0x525080 | |
REFCNT = 1 | |
FLAGS = (PADBUSY,PADMY,POK,pPOK,UTF8) | |
PV = 0x517f00 "{\"a\":\"b\",\"c\":\"\343\201\202\"}"\0 [UTF8 "{"a":"b","c":"\x{3042}"}"] | |
CUR = 19 | |
LEN = 20 | |
===================================== | |
a | |
===================================== | |
SV = PVMG(0x551130) at 0x525080 | |
REFCNT = 1 | |
FLAGS = (PADBUSY,PADMY,SMG,POK,pPOK,UTF8) | |
IV = 0 | |
NV = 0 | |
PV = 0x517f00 "{\"a\":\"b\",\"c\":\"\343\201\202\"}"\0 [UTF8 "{"a":"b","c":"\x{3042}"}"] | |
CUR = 19 | |
LEN = 20 | |
MAGIC = 0x557120 | |
MG_VIRTUAL = &PL_vtbl_utf8 | |
MG_TYPE = PERL_MAGIC_utf8(w) | |
MG_LEN = 17 | |
MG_PTR = 0x51a1b0 | |
0: 2 -> 2 | |
1: 15 -> 17 | |
===================================== | |
a": | |
===================================== |
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
% perl -v | |
This is perl, v5.8.8 built for i386-linux-thread-multi | |
Copyright 1987-2006, Larry Wall | |
Perl may be copied only under the terms of either the Artistic License or the | |
GNU General Public License, which may be found in the Perl 5 source kit. | |
Complete documentation for Perl, including FAQ lists, should be found on | |
this system using "man perl" or "perldoc perl". If you have access to the | |
Internet, point your browser at http://www.perl.org/, the Perl Home Page. | |
% perl ~/substr_bug.pl | |
SV = PV(0x9e96b00) at 0x9e96750 | |
REFCNT = 1 | |
FLAGS = (PADBUSY,PADMY,POK,pPOK,UTF8) | |
PV = 0x9eacde8 "{\"a\":\"b\",\"c\":\"\343\201\202\"}"\0 [UTF8 "{"a":"b","c":"\x{3042}"}"] | |
CUR = 19 | |
LEN = 20 | |
===================================== | |
a | |
===================================== | |
SV = PVMG(0x9eab938) at 0x9e96750 | |
REFCNT = 1 | |
FLAGS = (PADBUSY,PADMY,SMG,POK,pPOK,UTF8) | |
IV = 0 | |
NV = 0 | |
PV = 0x9eacde8 "{\"a\":\"b\",\"c\":\"\343\201\202\"}"\0 [UTF8 "{"a":"b","c":"\x{3042}"}"] | |
CUR = 19 | |
LEN = 20 | |
MAGIC = 0x9ef4d08 | |
MG_VIRTUAL = &PL_vtbl_utf8 | |
MG_TYPE = PERL_MAGIC_utf8(w) | |
MG_LEN = 17 | |
MG_PTR = 0x9ed21d8 | |
0: 2 -> 2 | |
1: 15 -> 17 | |
===================================== | |
a | |
===================================== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment