in reply to Having trouble with changing $1 of a regex
Hi, i have a need to change matches from a regex, to be changed on the fly, in the replace section.
That is as clear as mud.
use strict; use warnings; use 5.010; my $string = 'a6a'; my $new_val = 9; $string =~ s/(\d+)/ $1 + $new_val /e; say $string; --output:-- a15a $string =~ s/(\d+)/ "hello$1world" /e; say $string; --output:-- ahello15worlda $string = 'aXXXa'; $string =~ s/(XXX)/ my $x = $1; #$1 is read only, so can't use s/// on it $x =~ s{X}{Y}g; #use a unique delimiter so no conflict $x #previous line returns # of substitutions /e; say $string; --output:-- aYYYa
|
|---|