in reply to Re^5: Composing regex's dynamically
in thread Composing regex's dynamically

You are asserting that any time you interpolate a compiled re into another, it just stringifies the first anyway, and re-compiles the whole thing?

I had always assumed that it copies the compiled bits and does not need to re-process it. I formed that opinion in the early days of the existence of qr, so that was a long time ago now.

Replies are listed 'Best First'.
Re^7: Composing regex's dynamically
by JavaFan (Canon) on Apr 30, 2011 at 13:12 UTC
    You are asserting that any time you interpolate a compiled re into another, it just stringifies the first anyway, and re-compiles the whole thing?
    That's no assertion. That's how it works.
    I had always assumed that it copies the compiled bits and does not need to re-process it.
    No, that's not really possible to do (think for instance paren counts - or consider this: $q = qr/x/; $r = qr/[$q]/). It only works in this case:
    my $qr1 = /pattern/; my $qr2 = /$qr1/;
    Use use re 'debug' and you will see what strings are being compiled.
Re^7: Composing regex's dynamically
by Anonymous Monk on Apr 30, 2011 at 13:18 UTC
    What JavaFan said
    $ perl -Mre=debug -e " $f = qr/./; warn if m/$f/" Compiling REx "." Final program: 1: REG_ANY (2) 2: END (0) minlen 1 Freeing REx: "." $ perl -Mre=debug -e " $f = qr/./; $g = qr/$f/; warn if m/$g/" Compiling REx "." Final program: 1: REG_ANY (2) 2: END (0) minlen 1 Freeing REx: "."
    $ perl -Mre=debug -e " $f = qr/./; $g = qr/./; $c=qr/$f$g/; " Compiling REx "." Final program: 1: REG_ANY (2) 2: END (0) minlen 1 Compiling REx "." Final program: 1: REG_ANY (2) 2: END (0) minlen 1 Compiling REx "(?-xism:.)(?-xism:.)" Final program: 1: REG_ANY (2) 2: REG_ANY (3) 3: END (0) minlen 2 Freeing REx: "." Freeing REx: "." Freeing REx: "(?-xism:.)(?-xism:.)"