How can I use Perl's s/// in an expression?
- by mikeY
I got a headache looking for this:
How do you use s/// in an expression as opposed to an assignment. To clarify what I mean, I'm looking for a perl equivalent of python's re.sub(...) when used in the following context:
newstring = re.sub('ab', 'cd', oldstring)
The only way I know how to do this in perl so far is:
$oldstring =~ s/ab/cd/;
$newstring = $oldstring;
Note the extra assignment.