in reply to Re: Is there a way to find out what kind of ref an object is? (isa)
in thread Is there a way to find out what kind of ref an object is?

neither are any of the techniques I've seen that aren't unreasonably complicated, unfortunately.

Is:

use Scalar::Util qw( reftype ); ... print "$ref is a ", reftype( $ref ), "\n";

unreasonably complicated?

  • Comment on Re^2: Is there a way to find out what kind of ref an object is? (isa)
  • Download Code

Replies are listed 'Best First'.
Re^3: Is there a way to find out what kind of ref an object is? (isa)
by tye (Sage) on Dec 07, 2005 at 19:41 UTC

    I guess you are assuming that it is perfect. But it isn't. It prevents you from properly handling overloaded objects that know how to act like a hash ref even though they aren't.

    Of course, it is also overly complicated in many cases. For example, on the version of Perl I have most handy, it simply dies with Can't locate Scalar/Util.pm and overcoming that is rather hugely complicated, as it happens.

    - tye        

      But it isn't. It prevents you from properly handling overloaded objects that know how to act like a hash ref even though they aren't.

      I'd interpreted the OP's requirement as not wanting this behaviour. YMMV.

      on the version of Perl I have most handy, it simply dies with Can't locate Scalar/Util.pm and overcoming that is rather hugely complicated, as it happens

      Fair point.

Re^3: Is there a way to find out what kind of ref an object is? (isa)
by chromatic (Archbishop) on Dec 07, 2005 at 16:57 UTC

    It has the misfortune of working correctly, as opposed to ref or UNIVERSAL::isa().

      It has the misfortune of working correctly, as opposed to ref or UNIVERSAL::isa().

      Oh I do agree that the number of times that you'd actually want to use reftype, outside pure curiosity and debugging, is pretty darn tiny. However, on the odd occasion when I do need it I find it fortunate to have something that does exactly the job I want and is named properly :-)