in reply to Check whether a variable is a hash or not
Just to expand a little on the helpful info you've already gotten from davorg and ikegami, ref and Scalar::Util's reftype will both tell you (1) whether what you have is a reference, and (2) what kind of reference it is. The difference between them is what they do with a reference that's been blessed into a class. In that case, ref will give you the class name, and reftype will tell you the type of the unblessed reference.
Here's an example:
use Scalar::Util qw( reftype ); my $blessed = bless {}, 'My::Class'; my $hashref = {}; printf "blessed is ref %s\n", ref $blessed; printf "blessed is reftype %s\n", reftype $blessed; printf "hashref is ref %s\n", ref $hashref; printf "hashref is reftype %s\n", reftype $hashref;
This prints:
blessed is ref My::Class blessed is reftype HASH hashref is ref HASH hashref is reftype HASH
Both of them will return undef if you hand them something that is not a reference. Otherwise what's returned is just a regular string that you can compare with eq or pattern matches.
|
|---|