http://qs1969.pair.com?node_id=217629


in reply to stringified references

From what I know you are almost correct. adrianh has the problem but missed* in the turgid docs of perldoc:overload the implication of overload::StrVal which will return the pattern you specify. If that changed an endless chunk of code would break. Including Data::Dumper. You, or I or someone should post a documentation patch to make it permanent however.

Heres a more rigourous definition of a is_blessed test.

$is_blessed = defined($x) && ref($x) && overload::StrVal($x) =~ /=/;
Incidentally for this check its faster but less idiomatic to say
$is_blessd=defined($x) && ref($x) && (index(overload::StrVal($x),'=')> +=0);
BTW, only if you choose to consider qr// constructs to be blessed then this test is fine. If you dont then you need something like
$is_blessd=defined($x) && ref($x) && (index(overload::StrVal($x),'=')> +=0) && overload::StrVal($x)!~/^Regexp=SCALAR/;
PS: Im hoping that its obvious that you have to use overload; for all of this.

Cheers,

update:* I didnt mean to imply that he was wrong about the Scalar::Util approach. However it is an extra module and the code I mention should be fine without it. Although it is a lot faster to use than all of the above.

--- demerphq
my friends call me, usually because I'm late....