On Thu, 24 Oct 2002, Damian Conway wrote:
: Adam D. Lopresto wrote:
:
: > Really what I've been wishing for was an operator (or whatever) to let me do an
: > s// without changing the variable.
:
: I would hope/expect that that's what the subroutine form of C<s> would do.
The problem with defining that as the primitive behavior is that some substitutions
are very much faster in place, and it would be difficult to capture.
: That is, it takes a string, a pattern, and a replacement string,
: and returns a new string with substitution performed (without affecting
: the original string):
:
: print 'He said "$( s($statement,/\.$/,"") )", but we didn't believe him.';
It's possible the syntax for substitution should be wrapped around the syntax
for matching, whatever that turns out to be.
replace($statement =~ /\.$/, "")
replace($statement like /\.$/, "")
or even:
replace($statement like /\.$/, with => "")
We shouldn't limit our notions to strings:
replace(@array like 1|2|3, $& + 1);
or if @array is the topic
replace(1|2|3, $& + 1)
It's not yet clear where in-place vs en-passant fits in here.
Perhaps there's two different functions, spliting replace into
"inplace" and "outplace". :-)
I'm sure there are better words with the right connotations though.
Larry