in reply to Massive regexp search and replace
This list can easily be used like this:#list of regex-strings my @regex = ( 's/(a+)/\U$1/g', 's/([bz]+)/XX/g', ); #is now a list of subroutines @regex = map { eval "\$sub = sub { \$_=\$_[0]; $_; \$_ }" } @regex;
Encapsulating the regexes in subroutines should be faster than recompiling the same regex again and again. Note, that I did no benchmarks.my @text = ( "aaaabbzz", "bbbyyy", ); for my $t ( @text ) { print "org $t\n"; for my $re ( @regex ) { $t = &$re($t); } print "new $t\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Massive regexp search and replace
by Tanktalus (Canon) on Feb 10, 2005 at 15:17 UTC |