Next | Regular Expression Mastery | 61 |
push @pats, qr/$_/ for 'fo*', 'ba.', 'w+3';
while (<>) { foreach $pat (@pats) { print if /$pat/; } }
Since 5.005, regexes are first-class objects
$regex = qr/REGEX/ yields a regex object
$string =~ /$regex/ does not perform another compilation
$string =~ $regex works also
This is about 80% faster
Next | Copyright © 2002 M. J. Dominus |