in reply to Regexp Speed Concerns
The really nice part is that, unlike most of the low-level debugging features, you don't need a DEBUGGING build of Perl to debug your regular expressions.Debugging regular expressions There are two ways to enable debugging output for regular expressions. If your perl is compiled with -DDEBUGGING, you may use the -Dr flag on the command line. Otherwise, one can use re 'debug', which has effects both at compile time, and at run time (and is not lexically scoped). [snip; read the details in the perldebug documentation.]
Here's the output from 5.005_03, reformatted for a little extra clarity:#!perl -c use re 'debug'; /at/||/bt/||/ct/||/dt/||/et/||/ft/||/ght/; /at|bt|ct|dt|et|ft|ght/; /[abcdef]t|ght/; /(?:[abcdef]|gh)t/; /(?:a|b|c|d|e|f|gt)t/; __END__
Of course, that's just how the regular expressions are compiled; to see how the regexes are matched -- which is where the optimizer really comes into play -- give the regexes something to match against and watch the output at runtime!/at/||/bt/||/ct/||/dt/||/et/||/ft/||/ght/; compiling RE `at' size 3 first at 1 1: EXACT <at>(3) 3: END(0) anchored `at' at 0 (checking anchored isall) minlen 2 compiling RE `bt' size 3 first at 1 1: EXACT <bt>(3) 3: END(0) anchored `bt' at 0 (checking anchored isall) minlen 2 compiling RE `ct' size 3 first at 1 1: EXACT <ct>(3) 3: END(0) anchored `ct' at 0 (checking anchored isall) minlen 2 compiling RE `dt' size 3 first at 1 1: EXACT <dt>(3) 3: END(0) anchored `dt' at 0 (checking anchored isall) minlen 2 compiling RE `et' size 3 first at 1 1: EXACT <et>(3) 3: END(0) anchored `et' at 0 (checking anchored isall) minlen 2 compiling RE `ft' size 3 first at 1 1: EXACT <ft>(3) 3: END(0) anchored `ft' at 0 (checking anchored isall) minlen 2 compiling RE `ght' size 4 first at 1 1: EXACT <ght>(4) 4: END(0) anchored `ght' at 0 (checking anchored isall) minlen 3 /at|bt|ct|dt|et|ft|ght/; compiling RE `at|bt|ct|dt|et|ft|ght' size 23 1: BRANCH(4) 2: EXACT <at>(23) 4: BRANCH(7) 5: EXACT <bt>(23) 7: BRANCH(10) 8: EXACT <ct>(23) 10: BRANCH(13) 11: EXACT <dt>(23) 13: BRANCH(16) 14: EXACT <et>(23) 16: BRANCH(19) 17: EXACT <ft>(23) 19: BRANCH(23) 20: EXACT <ght>(23) 23: END(0) minlen 2 /[abcdef]t|ght/; compiling RE `[abcdef]t|ght' size 18 1: BRANCH(14) 2: ANYOF(12) 12: EXACT <t>(18) 14: BRANCH(18) 15: EXACT <ght>(18) 18: END(0) minlen 2 /(?:[abcdef]|gh)t/; compiling RE `(?:[abcdef]|gh)t' size 18 1: BRANCH(12) 2: ANYOF(16) 12: BRANCH(15) 13: EXACT <gh>(16) 15: TAIL(16) 16: EXACT <t>(18) 18: END(0) minlen 2 /(?:a|b|c|d|e|f|gt)t/; compiling RE `(?:a|b|c|d|e|f|gt)t' size 25 1: BRANCH(4) 2: EXACT <a>(23) 4: BRANCH(7) 5: EXACT <b>(23) 7: BRANCH(10) 8: EXACT <c>(23) 10: BRANCH(13) 11: EXACT <d>(23) 13: BRANCH(16) 14: EXACT <e>(23) 16: BRANCH(19) 17: EXACT <f>(23) 19: BRANCH(22) 20: EXACT <gt>(23) 22: TAIL(23) 23: EXACT <t>(25) 25: END(0) minlen 2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regexp Speed Concerns
by tadman (Prior) on Jan 13, 2001 at 03:31 UTC | |
by tilly (Archbishop) on Jan 13, 2001 at 04:24 UTC |