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.
A reference type refers to an object in some external memory space. This is in contrast to value types, that are stored where they are created. Experts also talk about reference types as being 'dynamically allocated.
Examples of reference types include: strings, arrays, objects of classes, etc.
A reference type variable contains a reference to data stored in memory, also known as the heap. The heap is most often used for data that has a longer life. You can have more than one variable point to the same referenced data. Objects are an example of a reference type.
Variables of reference types store references to their data (objects), while variables of value types directly contain their data. With reference types, two variables can reference the same object; therefore, operations on one variable can affect the object referenced by the other variable.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With