So there's really two questions here.
The first is why wasn't COW used for matching half of the code.
COW is normally used for the copy for $& and friends, but it wasn't used in this case because there's not enough space in the buffer.
CUR = 100 LEN = 101
I think two bytes are needed. One for the NUL, and one for the COW reference count. Replace $_ .= "x"; with chop;, and you get:
SV = PV(0x5deca7958ee0) at 0x5deca7994d68 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x5deca7998850 "xxxxxxxxxx"...\0 CUR = 98 LEN = 101 SV = PV(0x5deca7958ee0) at 0x5deca7994d68 REFCNT = 1 FLAGS = (POK,IsCOW,pPOK) PV = 0x5deca7998850 "xxxxxxxxxx"...\0 CUR = 98 LEN = 101 COW_REFCNT = 1 SV = PV(0x5deca7958ee0) at 0x5deca7994d68 REFCNT = 1 FLAGS = (POK,IsCOW,pPOK) PV = 0x5deca797ad20 "aaa"\0 CUR = 3 LEN = 16 COW_REFCNT = 1
The second question is why does the scalar get a new buffer for the substitution.
I'm guessing the buffer of the scalar is stolen rather than copied for $& and friends, since the expectation is that it will change.
That means the scalar always gets a new buffer.
In reply to Re^5: 5.42: Does m// toss a string around?
by ikegami
in thread 5.42: Does m// toss a string around?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |