in reply to Internal representation of qr// compiled regular expressions

Go to the p5p archive and do a case-sensitive search for "ref Regexp" (for example) to find quite a few interesting items on this subject.

There have been attempts to change it to Regex, REGEX, or REGEXP.

Also, note that UNIVERSAL::isa(qr/hi/,"SCALAR") returns true so that the regex is actually a blessed reference to a scalar (yes, I peek under the covers all the time).

        - tye (but my friends call me "Tye")
  • Comment on (tye)Re: Internal representation of qr// compiled regular expressions

Replies are listed 'Best First'.
Re: (tye)Re: Internal representation of qr// compiled regular expressions
by John M. Dlugosz (Monsignor) on Jun 28, 2001 at 01:01 UTC
    A regex object is actually a blessed reference to a scalar: interesting. That's what japhy's dump shows, too. But what's in that scalar? It seems to have a overloaded "" that decodes the compiled expression back into a string, but the dump, as does an explicit ${qr/a/}, shows that nothing is stored in that scalar. It's not a pointer to a C structure, or byte code in the SV, or whatnot. It's a PVMG, whatever that is (not documented in Devel::Peek nor perlguts).

    —John

      pp_ctl.c (in pp_regcomp()) shows that, if the regex has magic on (which means it's a qr// regex), it extracts the regexp struct from mg->mg_obj. So that's where the "meat" of a Regexp object is.

      Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
      How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
        Wow, has it really been nearly five years?!

        So, is the mg_obj member in a different place from where normal representations are stored for scalars? Point is, I guess, is that it's done in a totally different way than just blessing a scalar, which is how we would do something within the Perl 5 language.

        —John