The key is to copy the data you want to preserve. If you need this kind of behaviour very often, write a simple subroutine that does what you want.
sub cdo(&$){ local $_ = $_[1]; $_[0]->(); $_ } my $foo = 'abc'; print cdo { s/abc/def/ } $foo; print "\n$foo\n";
TI, of course, MTOWTDI.
In reply to Re: Non-destructive string substitution
by fruiture
in thread Non-destructive string substitution
by Sprad
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |