Thanks for clarification. I.e. we better be careful with 4-args (or LHS) variant of substr?
It's funny, Perl rightfully decides (case "0") it's cheaper to move 499_998 initial bytes _up_ than moving the trailing 500_000 bytes _down_ (and so scalar gets OOK-"contaminated"); and it's the opposite (rightfully) for "2" -- scalar stays OOK-free & usable OK with regex engine. When ("1") they are both 499_999, then... -- ??? move the 1st half UP and actually _complicate_ things! (do additional work of setting the OFFSET?)
use Devel::Peek;
$Devel::Peek::pv_limit = 1;
for ( 0 .. 2 ) {
my $s = 'a' x 1e6;
substr $s, 499_998 + $_, 2, 'b';
Dump $s;
}
__END__
SV = PV(0xdbb198) at 0x26f8ae0
REFCNT = 1
FLAGS = (POK,OOK,pPOK)
OFFSET = 1
PV = 0x2954309 ( ""... . ) "a"...\0
CUR = 999999
LEN = 1000001
SV = PV(0xdbb198) at 0x26f8ae0
REFCNT = 1
FLAGS = (POK,OOK,pPOK)
OFFSET = 1
PV = 0x2954309 ( ""... . ) "a"...\0
CUR = 999999
LEN = 1000001
SV = PV(0xdbb198) at 0x26f8ae0
REFCNT = 1
FLAGS = (POK,pPOK)
PV = 0x2954308 "a"...\0
CUR = 999999
LEN = 1000002