in reply to (tye)Re: Internal representation of qr// compiled regular expressions
in thread Internal representation of qr// compiled regular expressions

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

  • Comment on Re: (tye)Re: Internal representation of qr// compiled regular expressions

Replies are listed 'Best First'.
Re^3: Internal representation of qr// compiled regular expressions
by japhy (Canon) on May 23, 2006 at 00:18 UTC
    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

        Yes. The stringification of a Regexp object goes through the magic system. The mg_obj member is how a Regexp object points to the internal representation of itself (the regexp struct).

        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