Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: How to differentiate hash reference and object reference?

by tlm (Prior)
on Aug 31, 2005 at 11:59 UTC ( [id://488079]=note: print w/replies, xml ) Need Help??


in reply to How to differentiate hash reference and object reference?

Check out Scalar::Util::blessed. You can also use UNIVERSAL::isa( $obj, 'foo' ).

the lowliest monk

Replies are listed 'Best First'.
Re^2: How to differentiate hash reference and object reference?
by xdg (Monsignor) on Aug 31, 2005 at 14:45 UTC

    Be very careful calling UNIVERSAL::isa as a function, though, and be sure that's what you want. It's nice in that you can throw any reference at it whether or not it's blessed, but it doesn't allow various facade or delegation patterns that don't rely on @ISA inheritance, but do override isa to signal that they do, indeed, subclass an object through other means. This is probably better (using blessed as recommended):

    blessed $obj && $obj->isa('foo')

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-03-28 08:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found