in reply to Dumping Compiled Regular Expressions

If you set $class to a more complicated re, you'll see something interesting:
my $class = 'Temp(a?)'; my $re = qr/test/io; my $regex = bless $re, $class; print "Verbatim: $regex\n"; print "Ref: ", ref($regex), "\n";
The 'class name' section of the reference actually contains regex characters. I'm not aware of any other way to check this than looking for invalid package name characters in the ref. Sorry.

Update: I completely misread the original question, and am now looking for a way to redeem myself by giving a *good* answer. :|

Check this out:

my $re = qr/(test)/io; print "Verbatim: $re\n"; print "Ref: ", ref($re), "\n";
It displays correctly unless you bless it into another class. Of course, it matches in both the qr and the re-blessed form, which indicates to me that *something* keeps track of whether or not it's a regex, no matter what class name it keeps around.

Replies are listed 'Best First'.
Re: Re: Dumping Compiled Regular Expressions
by Hrunting (Pilgrim) on Nov 21, 2000 at 01:28 UTC
    Hmm, I may not have stated my original question clearly enough. Basically, my script is going to get an object. That object could be blessed into any class (not a name of my choosing), and that object could be a blessed reference of any kind. Most of the time, that's not a problem, but apparently these two lines will produce almost exactly the same output (only addresses will differ):
    my $re = qr/temp/i; bless $re, $class;
    my $var = 'temp';   bless $var, $class;
    
    Both of those objects, when looked at using ref() will be of class '$class' (in this case, say 'Temp'). Both of those objects, when looked at using scalar(), will appear as something like '$class=SCALAR(0x00000)' ($class could be 'Temp' or it could be whatever $class was; again, that's up to the object's original class). I guess my real question is, is there some other way to obtain information on that blessed value that I'm missing?