> It might also be worth mentioning Scalar::Util's reftype() and blessed() > which are unambiguous in their functionality and often what people really > should be using mean when use ref(), Arguably ref() should be deprecated and blessed() and reftype() moved into core. isa() is an unsatisfactory means of determing variable type, as is ref(). Also, as the pseudo-class Regexp is actually a core class facilitated by magic it should not return SCALAR as its reftype. IMO it should return REGEX instead. (And it should be possible to strigify it when blessed without reblessing it into the class 'Regexp'. I have a patch for Scalar::Util to do this, but its odd to me that the core logic doesnt handle this more smoothly.) Also while considering hariy cases like the class "\0", "", and 0 some thought might go into being allowed to bless into the packages HASH, ARRAY, SCALAR, etc. Getting rid of this would remove the hairy edge cases, of course it would also remove the easiest workaround when someone does use ref as a type checker or makes other such mistakes. (For instance older versions of B::Deparse wouldnt dump blessed code refs.) Heres an example of hairyness: use Scalar::Util qw(reftype blessed); use UNIVERSAL qw(isa); my $o=bless qr/^\d+$/,'HASH'; print "It ",isa($o,'HASH') ? "is" : "isn't", " a HASH\n"; print "It ",'1234'=~/$o/ ? "does" : "doesn't", " match '1234'\n"; print "It ",'ABCD'=~/$o/ ? "does" : "doesn't", " match 'ABCD'\n"; print "It stringifies as $o reftype is ", reftype($o)," and is blessed as ",blessed($o),"\n"; bless $o,'Regexp'; print "It stringifies as $o reftype is ", reftype($o)," and is blessed as ",blessed($o),"\n"; __END__ It is a HASH It does match '1234' It doesn't match 'ABCD' It stringifies as HASH=SCALAR(0x1acefd4) reftype is SCALAR and is blessed as HASH It stringifies as (?-xism:^\d+$) reftype is SCALAR and is blessed as RegexpThread Previous | Thread Next