Oh! Another to fix the problem is to add a no-op to the regexp.
$\ = "\n"; $pat = 'b'; $_='abc'; s/$pat/!/g; print; $pat = ''; $_='abc'; s/$pat/@/g; print; $pat = ''; $_='abc'; s/(?:$pat)/#/g; print;
outputs
a!c a@c #a#b#c#
In reply to Re^2: s/// with an empty pattern uses the previous pattern of a s///
by ikegami
in thread s/// with an empty pattern uses the previous pattern of a s///
by ckeith100
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |