Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Identifying if a variable is the product of a qr//

by Juerd (Abbot)
on Apr 25, 2002 at 10:13 UTC ( [id://161906]=note: print w/replies, xml ) Need Help??


in reply to Identifying if a variable is the product of a qr//

It doesn't matter. As soon as you bless it into another package, it is no longer a precompiled regex, but a reference to an undefined scalar (Dumper isn't handling this incorrectly, the scalar actually is undef).

This is normal behaviour. If $object is blessed into Foo, and you re-bless it into Bar, it is no longer an object of class Foo.

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.

  • Comment on Re: Identifying if a variable is the product of a qr//

Replies are listed 'Best First'.
Re: Re: Identifying if a variable is the product of a qr//
by demerphq (Chancellor) on Apr 25, 2002 at 10:21 UTC
    As soon as you bless it into another package, it is no longer a precompiled regex,but a reference to an undefined scalar (Dumper isn't handling this incorrectly, the scalar actually is undef).

    Er, no (although thats what I thought at first too, run the code I provided.) It still is a precompiled regex otherwise it wouldn't match as it did in my example code.

    This is normal behaviour. If $object is blessed into Foo, and you re-bless it into Bar, it is no longer an object of class Foo.

    The results that I got in the code I posted suggest that in fact a regex is a base type like array or hash and thus its underlying behaviour does not change as it is blessed and reblessed.

    Oh and it gets weirder, there is no way using UNIVERSAL::isa() to determine if a blessed scalar ref is a regex.

    Yves / DeMerphq
    ---
    Writing a good benchmark isnt as easy as it might look.

      although thats what I thought at first too, run the code I provided.

      Did run it, but didn't notice the scalar ref matching correctly.

      Using Devel::Peek, you can clearly see there is something MAGICal going on, maybe it helps...

      2;1 juerd@ouranos:~$ cat dm use Devel::Peek; print Dump bless qr/foo/, 'foo'; print Dump bless \my $foo, 'foo'; 2;0 juerd@ouranos:~$ perl dm SV = RV(0x810b404) at 0x80f60ac REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x80f61a8 SV = PVMG(0x8101b30) at 0x80f61a8 REFCNT = 1 FLAGS = (OBJECT,RMG) IV = 0 NV = 0 PV = 0 MAGIC = 0x80fffe0 MG_VIRTUAL = 0x80f4f74 MG_TYPE = 'r' MG_OBJ = 0x8100160 STASH = 0x80fd414 "foo" SV = RV(0x810b404) at 0x80f60ac REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x80fd450 SV = PVMG(0x8101b30) at 0x80fd450 REFCNT = 2 FLAGS = (PADBUSY,PADMY,OBJECT) IV = 0 NV = 0 PV = 0 STASH = 0x80fd414 "foo"

      - Yes, I reinvent wheels.
      - Spam: Visit eurotraQ.
      

        I guess it's the MG_TYPE='r' line which is indicating it's a magical Regexp, and the magic isn't affected when it's bless'ed.

        A quick look through my copy of perlguts however reveals that.. err.. r isn't listed as a possible value of MG_TYPE.

        Now planning on hitting Inline::CPP a bit more when I get home see if I can magically regexp'ify strings and visa-versa..

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://161906]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (7)
As of 2024-04-23 12:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found