Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: stringified references

by demerphq (Chancellor)
on Dec 04, 2002 at 23:51 UTC ( [id://217629]=note: print w/replies, xml ) Need Help??


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....

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-20 04:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found