in reply to Behaving appropriately based on ref() result

You could also use the reftype function from Scalar::Util. This has the advantage of

  1. Explicitly returning undef on a non-reference variable
  2. Returning the underlying data structure type when handed an object

for example:

use Scalar::Util qw(reftype); my $o=bless {},MyClass; print ref $o # prints "MyClass" print reftype($o) # prints "HASH"

There are ten types of people: those that understand binary and those that don't.