shadowSage has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Optimization of Regexes
by ikegami (Patriarch) on Sep 22, 2014 at 12:44 UTC | |
by shadowSage (Novice) on Sep 22, 2014 at 13:52 UTC | |
by ikegami (Patriarch) on Sep 22, 2014 at 14:14 UTC | |
by shadowSage (Novice) on Sep 22, 2014 at 14:24 UTC | |
by ikegami (Patriarch) on Sep 22, 2014 at 15:27 UTC | |
by locked_user sundialsvc4 (Abbot) on Sep 22, 2014 at 14:19 UTC |