Wednesday, August 11, 2010

Copying and Substituting Simultaneously

When the purpose is to search and replace a copy of the string and the intention is to accomplish this in one step then instead of doing this:
$dst = $src;
$dst =~ s/this/that/;
a single step like this will be more concise:
($dst = $src) =~ s/this/that/;

No comments: