I wanted to use embedded code ... Now I can optimize a lot of my regexes with it.
Beware. Such "optimization" is often a snare and a delusion. Many times it is more conducive to efficiency to understand how the Perl regex engine captures and returns groups and to take advantage of these inherent mechanisms. Also be aware that previous to Perl version 5.18 (I think), there existed a bug that caused weird interactions between embedded regex code and "external" (if that's the right term) my variables.
OTOH of course, sometimes embedded code is just the only way to do it. :)
Give a man a fish: <%-{-{-{-<
| [reply] [d/l] |
Adding code ("actions") into your patterns is how real-world parser generators generally work. Perl6 has gone that direction, but the Perl5 syntax for doing it is obscenely bletcherous.
| [reply] |
Yes, I've looked into the perlretut (or something, forgot) section. It said, that it's a new buggy feature.
But, I kind of dreamed of feature like that, because, I have one megapattern, in one of my programs, that I've had to create an entire subroutine for it to parse with many different regexes and ifs thenths, that spans for about 3 screen pages. I was hoping for a feature like this to make that pattern matching subroutine to make more consize.
I think, in that sub's case, I am targetting not the speed, but readability and managedness of the code :)
| [reply] |
At that point (three pages of parsing regexps), I think you are well into the territory where you should use a grammar engine. For instance, Parse-RecDescent, or my preferred, Marpa-R2
| [reply] |