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
In reply to Re: Having trouble with changing $1 of a regex
by 7stud
in thread Having trouble with changing $1 of a regex
by perlint
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |