G
Graham Gough
I have been trying to solve a problem in which I wish to substitute
for *almost* all occurrences of a regular expression. For example all
occurrences of \d\d\d\d except some specific ones. I ended up with
using the e modifier and code like that given below, but had a nagging
felling that there was probably some more elegant method. Anyone any
suggestions?
Graham
$text =~ s/(\d\d\d\d)/&choose($1,"1234")/ge;
sub choose {
my $val = shift;
my $notpat = shift;
my $ret=$val;
if (!($val =~ /$notpat/)) {
$ret = "XX" . $ret . "XX";
}
return $ret;
}
for *almost* all occurrences of a regular expression. For example all
occurrences of \d\d\d\d except some specific ones. I ended up with
using the e modifier and code like that given below, but had a nagging
felling that there was probably some more elegant method. Anyone any
suggestions?
Graham
$text =~ s/(\d\d\d\d)/&choose($1,"1234")/ge;
sub choose {
my $val = shift;
my $notpat = shift;
my $ret=$val;
if (!($val =~ /$notpat/)) {
$ret = "XX" . $ret . "XX";
}
return $ret;
}