Reputation: 5698
Is there any function available in Perl to check the reference type:
my $ref=\@array;
I need to get the reference type as array
by the function.
Upvotes: 14
Views: 11485
Reputation: 11007
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.
Upvotes: 30