in reply to Re^2: Problem with capturing all matches with regex
in thread Problem with capturing all matches with regex

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:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^4: Problem with capturing all matches with regex
by Anonymous Monk on Oct 12, 2016 at 17:52 UTC
    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.
Re^4: Problem with capturing all matches with regex
by igoryonya (Pilgrim) on Oct 13, 2016 at 01:37 UTC
    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 :)

      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

      Good Day,
          Dean

        Seams, like grammar engine is a cool thing, but I am not getting it.
        I've read descriptions and readmes about both libraries that You've suggested, but the only thing that I can find, is that they are for source code parcing.
        Looked at term "grammar engine" on the inet and on wikipedia. Found nothing useful, and pretty much the same, as what I've said above.
        How is it compared to regex?