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

  • Comment on Re: How to differentiate hash reference and object reference?

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.