in reply to Re^3: 5.42: Does m// toss a string around?
in thread 5.42: Does m// toss a string around?
(OK, the PV method doesn't matter) I thought I got it (s/// implies matching; and $& and friends COW-share, in a way, original buffer; hence replacement operator (after 5.18) always re-allocates) but now I think the following example shows "match and manually replace" doesn't force re-allocation, then why s/// does?
use Devel::Peek qw( Dump ); $Devel::Peek::pv_limit = $Devel::Peek::pv_limit = 10; $_ = "x" x 99; $_ .= "x"; # Force unsharing. Dump( $_ ); /(.+)/; Dump( $_ ); $_ = 'aaa'; Dump( $_ ); print "\n\n"; $_ = "x" x 99; $_ .= "x"; # Force unsharing. Dump( $_ ); s/(.+)/aaa/; Dump( $_ ); __END__ 5.042000 SV = PV(0x1e2951e23e0) at 0x1e29521d298 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x1e295228ad0 "xxxxxxxxxx"...\0 CUR = 100 LEN = 101 SV = PV(0x1e2951e23e0) at 0x1e29521d298 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x1e295228ad0 "xxxxxxxxxx"...\0 CUR = 100 LEN = 101 SV = PV(0x1e2951e23e0) at 0x1e29521d298 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x1e295228ad0 "aaa"\0 CUR = 3 LEN = 101 SV = PV(0x1e2951e23e0) at 0x1e29521d298 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x1e295228ad0 "xxxxxxxxxx"...\0 CUR = 100 LEN = 101 SV = PV(0x1e2951e23e0) at 0x1e29521d298 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x1e295215d60 "aaa"\0 CUR = 3 LEN = 16
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: 5.42: Does m// toss a string around?
by ikegami (Patriarch) on Jan 30, 2026 at 18:59 UTC | |
by Anonymous Monk on Jan 30, 2026 at 22:37 UTC | |
by Anonymous Monk on Jan 30, 2026 at 22:47 UTC |