in reply to Re: How do I assign & substitute in one statement?
in thread How do I assign & substitute in one statement?
You would need to create a copy before modifying. One way:
Another:($sEnd) = map {s/hello/goodbye/g; $_;} map {$_} ($sBegin);
A functionally similar solution that doesn't use map:($sEnd) = map {s/hello/goodbye/g; $_;} @{[$sBegin]};
Of course, creating a copy and working on it is the canonical solution:$sEnd = do {local $_ = $sBegin; s/hello/goodbye/g; $_;};
(my $sEnd = $sBegin) =~ s/hello/goodbye/g;
|
|---|