in reply to Re: Can we make $& better?
in thread Can we make $& better?
Some code is surely using that.$\ = "\n"; my $s = 'abcdefghij'; $s =~ s/def/123/; print $&; # def print substr($s, $-[0], $+[0] - $-[0]); # 123
The problem with $& and friends isn't the location of the partial strings but the semantics that require copying the parts. Thus for every match, the entire string must be copied.
Anecdote:
AnnoA poster on clpmisc complained that his program "stopped working" after he introduced use English. He was matching a short pattern against some monster genome string (one or two GB) with a reasonable number of matches (some 10_000). Copying killed the cat, to coin a phrase.
|
---|