in reply to Precompiling substitution regex
Newbie to Perl, but just found myself in similar circumstances. For what it's worth, I'm using a two dimensional array with map, i.e.,
my @SUB_REC = map {[qr{$_->[0]}, $_->[1]]} ( ['(robert|bobby)', 'bob'] );
where the first element of each row is the regex and the second element is the substitution. Then simply use
foreach (@SUB_REC) { $yourText =~ s/$_->[0]/$_->[1]/g; }
Obviously you can add more elements to the array for flags.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Precompiling substitution regex
by AnomalousMonk (Archbishop) on Jul 02, 2014 at 13:42 UTC | |
by Anonymous Monk on Jul 02, 2014 at 13:48 UTC | |
by Anonymous Monk on Jul 02, 2014 at 14:58 UTC | |
by AnomalousMonk (Archbishop) on Jul 02, 2014 at 21:50 UTC | |
|
Re^2: Precompiling substitution regex
by Anonymous Monk on Jul 26, 2019 at 06:02 UTC |