tags:

views:

57

answers:

1

Is there any function available in perl to check the reference type.

my $ref=\@array;

Here I need to get the reference type as array by the function.

+9  A: 

Use function ref:

$ref_type = ref $ref;

The return value is the one of: SCALAR, ARRAY, HASH, CODE (reference to subprogram), GLOB (reference to typeglob) and REF (reference to reference).

Actually, ref function may return more values and in case of reference to object returns package name instead of type: http://perldoc.perl.org/functions/ref.html.

Pmod
Note the reference has been blessed, ref() returns the package name, not the underlying data-type. In such cases, you might consider using Scalar::Util's reftype and blessed methods.
snoopy
@snoopy Though, most of the time it's more useful to know the package name (class) of the object. And you shouldn't be messing with the object internals manually anyway.
slebetman