Hi Perl Monks. Got another one to lay on you: In the 'Intermediate Perl' book, it is discussing the Regexp::Assemble module.
After the brief discussion of how it optimizes the expression it says 'If you are using v5.10 or later, Perl already does this for you.'
I did a quick (not exactly comprehensive) script to check what that statement was on about
use 5.020; use Regexp::Assemble; my $re = Regexp::Assemble->new; for('blah', 'bleh', 'chicken', 'woofie', 'snake', 'snakes', 'woofies', + 'chicken-woofy'){ $re->add("\Q$_"); } say $re->re; my $newre = qr/blah|bleh|chicken|woofie|snake|snakes|woofies|chicken-w +oofy/; say $newre;
The result:
(?^:(?:chicken(?:-woofy)?|woofies?|bl[ae]h|snakes?)) (?^u:(blah)|(bleh)|(chicken)|(woofie)|(snake)|(snakes)|(woofies)|(chic +ken-woofy))
What's the deal? Does it just happen internally when /matching|substituting/? Or do I have the wrong idea completely?
Thanks for your time in reading this
In reply to Optimization of Regexes by shadowSage
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |