in reply to How to view contents of a blessed Regular Expression?

Stringifying a regular expression seems to yield its string contents. So you could use that: (in the debugger)
DB<3> $x = qr/.+2/ DB<4> x "$x" 0 '(?-xism:.+2)' DB<5> $y = bless \$x, 'Foo' DB<6> x $y 0 Foo=SCALAR(0x140263050) DB<7> x "$$y" 0 '(?-xism:.+2)'

I've seen no documentation of this, so I wouldn't count on it. But it does work for me (with 5.005_03).

Replies are listed 'Best First'.
Re: Re: How to view contents of a blessed Regular Expression?
by nysus (Parson) on Jul 16, 2001 at 19:17 UTC
    Hmmm, doesn't work for me using ActiveState Perl 5.6.1. I wonder if it makes a difference that I'm blessing it in the context of an eval{} function like so:
    eval { bless qr/$pattern/, ref($class) || $class };
    I'm finding this all very confusing and I should probably just forget about such a minor thing.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop";
    $nysus = $PM . $MCF;
    Click here if you love Perl Monks

      qr// gives you a reference to a scalar that is already blessed into the Regexp package. So you are reblessing it which stops Regexp methods/overloads from working on it after that point. Stringification is a Regexp overload and so no longer works. If you want stringification again, then you'd need to provide such a overload via your AltRegex package.

              - tye (but my friends call me "Tye")
        But if you inherit from Regexp, wouldn't the overload be inherited as well? i.e. this works:

        use strict; $^W++; package A; use overload '""' => sub { overload::StrVal(shift) . 'xx' }; package B; @B::ISA = 'A'; package main; my $a = bless \(my $aa = 'abc'), 'A'; print "$a\n"; bless $a, 'B'; # re-bless print "$a\n";