Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
and requires only one compiled regexp per pattern, instead of many as the current scheme dictates (embedding a qr// in a larger pattern results in a complete recompile).
It was my understanding that this wasn't true - that no recompile took place when nesting with (??{}), and testing seems to bear this out:
$ perl -we'use re "debug"; $x=qr/(.)\1|(.)(??{$x})\2/; "abcddcba" =~ / +^$x\z/' Compiling REx `(.)\1|(.)(??{$x})\2' size 20 Got 164 bytes for offset annotations. 1: BRANCH(9) 2: OPEN1(4) 4: REG_ANY(5) 5: CLOSE1(7) 7: REF1(20) 9: BRANCH(20) 10: OPEN2(12) 12: REG_ANY(13) 13: CLOSE2(15) 15: LOGICAL[2](16) 16: EVAL(18) 18: REF2(20) 20: END(0) minlen 1 with eval Offsets: [20] 0[0] 1[1] 0[0] 2[1] 3[1] 0[0] 4[2] 0[0] 6[1] 7[1] 0[0] 8[1] 9[1] 0 +[0] 17[0] 17[0] 0[0] 18[2] 0[0] 20[0] Compiling REx `^(?-xism:(.)\1|(.)(??{$x})\2)\z' size 23 Got 188 bytes for offset annotations. first at 2 1: BOL(2) 2: BRANCH(10) 3: OPEN1(5) 5: REG_ANY(6) 6: CLOSE1(8) 8: REF1(22) 10: BRANCH(21) 11: OPEN2(13) 13: REG_ANY(14) 14: CLOSE2(16) 16: LOGICAL[2](17) 17: EVAL(19) 19: REF2(22) 21: TAIL(22) 22: EOS(23) 23: END(0) floating `'$ at 1..2147483647 (checking floating) anchored(BOL) minlen + 1 with eval Offsets: [23] 1[1] 9[1] 10[1] 0[0] 11[1] 12[1] 0[0] 13[2] 0[0] 15[1] 16[1] 0[0] +17[1] 18[1] 0[0] 26[0] 26[0] 0[0] 27[2] 0[0] 28[0] 30[2] 32[0] Guessing start of match, REx `^(?-xism:(.)\1|(.)(??{$x})\2)\z' against + `abcddcba'... Found floating substr `'$ at offset 8... Guessed: match at offset 0 Matching REx `^(?-xism:(.)\1|(.)(??{$x})\2)\z' against `abcddcba' Setting an EVAL scope, savestack=15 0 <> <abcddcba> | 1: BOL 0 <> <abcddcba> | 2: BRANCH Setting an EVAL scope, savestack=21 0 <> <abcddcba> | 3: OPEN1 0 <> <abcddcba> | 5: REG_ANY 1 <a> <bcddcba> | 6: CLOSE1 1 <a> <bcddcba> | 8: REF1 failed... 0 <> <abcddcba> | 11: OPEN2 0 <> <abcddcba> | 13: REG_ANY 1 <a> <bcddcba> | 14: CLOSE2 1 <a> <bcddcba> | 16: LOGICAL[2] 1 <a> <bcddcba> | 17: EVAL re_eval 0x1003bb30 Entering embedded `(.)\1|(.)(??{$x})\2' Setting an EVAL scope, savestack=35 1 <a> <bcddcba> | 1: BRANCH Setting an EVAL scope, savestack=41 1 <a> <bcddcba> | 2: OPEN1 1 <a> <bcddcba> | 4: REG_ANY 2 <ab> <cddcba> | 5: CLOSE1 2 <ab> <cddcba> | 7: REF1 failed... 1 <a> <bcddcba> | 10: OPEN2 1 <a> <bcddcba> | 12: REG_ANY 2 <ab> <cddcba> | 13: CLOSE2 2 <ab> <cddcba> | 15: LOGICAL[2] 2 <ab> <cddcba> | 16: EVAL re_eval 0x10019550 Entering embedded `(.)\1|(.)(??{$x})\2' Setting an EVAL scope, savestack=55 2 <ab> <cddcba> | 1: BRANCH Setting an EVAL scope, savestack=61 2 <ab> <cddcba> | 2: OPEN1 2 <ab> <cddcba> | 4: REG_ANY 3 <abc> <ddcba> | 5: CLOSE1 3 <abc> <ddcba> | 7: REF1 failed... 2 <ab> <cddcba> | 10: OPEN2 2 <ab> <cddcba> | 12: REG_ANY 3 <abc> <ddcba> | 13: CLOSE2 3 <abc> <ddcba> | 15: LOGICAL[2] 3 <abc> <ddcba> | 16: EVAL re_eval 0x10019550 Entering embedded `(.)\1|(.)(??{$x})\2' Setting an EVAL scope, savestack=75 3 <abc> <ddcba> | 1: BRANCH Setting an EVAL scope, savestack=81 3 <abc> <ddcba> | 2: OPEN1 3 <abc> <ddcba> | 4: REG_ANY 4 <abcd> <dcba> | 5: CLOSE1 4 <abcd> <dcba> | 7: REF1 5 <abcdd> <cba> | 20: END Setting an EVAL scope, savestack=95 restoring \1 to 2(2)..-1 restoring \2 to 2(2)..3 5 <abcdd> <cba> | 18: REF2 6 <abcddc> <ba> | 20: END Setting an EVAL scope, savestack=109 restoring \1 to 1(1)..-1 restoring \2 to 1(1)..2 6 <abcddc> <ba> | 18: REF2 7 <abcddcb> <a> | 20: END Setting an EVAL scope, savestack=123 restoring \1 to 0(0)..-1 restoring \2 to 0(0)..1 7 <abcddcb> <a> | 19: REF2 8 <abcddcba> <> | 22: EOS 8 <abcddcba> <> | 23: END Match successful! Freeing REx: `"^(?-xism:(.)\\1|(.)(??{$x})\\2)\\z"' Freeing REx: `"(.)\\1|(.)(??{$x})\\2"'

In reply to Re: Perl6ish rules in Perl5's regex engine by ysth
in thread Perl6ish rules in Perl5's regex engine by demerphq

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-03-28 18:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found