"be consistent" | |
PerlMonks |
Re: Parser Performance Questionby kcott (Archbishop) |
on Oct 05, 2017 at 00:48 UTC ( [id://1200706]=note: print w/replies, xml ) | Need Help?? |
G'day songmaster, As LanX alluded to in his update, I suspect the /o modifier may be the issue: it certainly stood out as I read through the code fragments you provided. In "perlre: Modifiers" you'll see: "o - pretend to optimize your code, but actually introduce bugs" That provides a link to further information in "perlop: Regexp Quote-Like Operators" but the fragment identifier (#s%2fPATTERN%2fREPLACEMENT%2fmsixpodualngcer) is wrong. The closest to that is probably #s/_PATTERN_/_REPLACEMENT_/msixpodualngcer; however, the one with the most information about /o, and probably more appropriate given the code you've shown, is #m/_PATTERN_/msixpodualngc, which culminates in: "The bottom line is that using /o is almost never a good idea." I probably would have created all of those regexes at compile time, and I would have used my instead of our variables. A dispatch table with actions based on matches may also be appropriate. You don't show sufficient code to make any direct modification recommendations. The following script simply suggests a technique you could adapt to your needs.
You may have sufficient, up-front knowledge about those "capture keys" to predefine an ordered @capture_keys rather than relying on the random list returned by keys. Output from a sample run of that script:
Update (minor code alteration): My original code had $capure_key (missing "t") throughout. I've changed that to $capture_key globally; retested; output unchanged. — Ken
In Section
Seekers of Perl Wisdom
|
|