szabgab has asked for the wisdom of the Perl Monks concerning the following question:

perl -Mre=debug -e '"hello world" =~ /l.w/'
will display debugging information about the matching process.

Is there a way to show the results in some other format (e.g. to include HTML markup?) Update: output of the above call added

Freeing REx: `","' Compiling REx `l.w' size 6 Got 52 bytes for offset annotations. first at 1 1: EXACT <l>(3) 3: REG_ANY(4) 4: EXACT <w>(6) 6: END(0) anchored `l' at 0 (checking anchored) minlen 3 Offsets: [6] 1[1] 0[0] 2[1] 3[1] 0[0] 4[0] Guessing start of match, REx `l.w' against `hello world'... Found anchored substr `l' at offset 2... Starting position does not contradict /^/m... Guessed: match at offset 2 Matching REx `l.w' against `llo world' Setting an EVAL scope, savestack=3 2 <he> <llo world> | 1: EXACT <l> 3 <hel> <lo world> | 3: REG_ANY 4 <hell> <o world> | 4: EXACT <w> failed... Setting an EVAL scope, savestack=3 3 <hel> <lo world> | 1: EXACT <l> 4 <hell> <o world> | 3: REG_ANY 5 <hello> < world> | 4: EXACT <w> failed... Setting an EVAL scope, savestack=3 9 <hello wor> <ld> | 1: EXACT <l> 10 <hello worl> <d> | 3: REG_ANY 11 <hello world> <> | 4: EXACT <w> failed... Match failed Freeing REx: `"l.w"'

Replies are listed 'Best First'.
Re: alternate markup for the 're' pragma
by demerphq (Chancellor) on Nov 12, 2006 at 16:47 UTC

    No there isn't. Although I've got plans for something that might make doing so easier.

    What part are you interested in BTW, the program dump or the execution diagnostics?

    ---
    $world=~s/war/peace/g

      At different times, I'm interested in both aspects.

      If you're pondering some sort of semantic markup, you may as well go the whole hog and emit XML. That way it can be styled and/or munged as appropriate. Mmm, that would open a lot of possibilities, no more icky screen-scraping.

      I want it.

      • another intruder with the mooring in the heart of the Perl

        Humm, thats an interesting idea. Ive been ponderng ways to allow more programatic introspection of compiled regexps. I have to admit I hadn't thought of XML, but it does make a certain amount of sense as it would be pretty easy to emit, albeit verbose.

        I was thinking of some kind of script that walked the regex optree and converted to perl structures so it can interfaced with from perl easily, but I suppose spitting out XML is another option.

        Interesting. Hmm.

        ---
        $world=~s/war/peace/g

      Right now I am mainly interested in the progress of the execution. To stick with the above example, the part that starts with "Setting an EVAL". (output added to the original post)

        What would be really useful is if you could describe a hypthetical interface by which you would get whatever information you want to get. Write a little program assuming that the interface works however you like and show it to me. My problem is that I'm far too close to the forest so to speak: When I think about what interfaces could be provided I just get overwhelmed by the options. Give me an idea of an api that you would like to work with and I have something concrete to aim for.

        ---
        $world=~s/war/peace/g

Re: alternate markup for the 're' pragma
by demerphq (Chancellor) on Nov 13, 2006 at 11:39 UTC

    Heres what it would look like with bleadperl (future 5.10):

    D:\dev\perl\ver\verbs\win32>..\perl -Mre=debug -e "'hello world' =~ /l +.w/" Compiling REx "l.w" Final program: 1: EXACT <l>(3) 3: REG_ANY(4) 4: EXACT <w>(6) 6: END(0) anchored "l" at 0 (checking anchored) minlen 3 Guessing start of match in sv for REx "l.w" against "hello world" Found anchored substr "l" at offset 2... Starting position does not contradict /^/m... Guessed: match at offset 2 Matching REx "l.w" against "llo world" 2 <he> <llo world> | 1:EXACT <l>(3) 3 <hel> <lo world> | 3:REG_ANY(4) 4 <hell> <o world> | 4:EXACT <w>(6) failed... 3 <hel> <lo world> | 1:EXACT <l>(3) 4 <hell> <o world> | 3:REG_ANY(4) 5 <hello> < world> | 4:EXACT <w>(6) failed... 9 <hello wor> <ld> | 1:EXACT <l>(3) 10 <hello worl> <d> | 3:REG_ANY(4) 11 <hello world> <> | 4:EXACT <w>(6) failed... Match failed Freeing REx: "l.w"

    But this pattern is IMO not a particularly good example. It doesn't use very sophisticated constructs so it doesnt illustrate the potential breadth of what someone could want to know. Something with lots of alternations and different quantifiers and dynamic patterns would be a much better example.

    ---
    $world=~s/war/peace/g