Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the type of the reference?

Tags:

perl

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.

like image 378
karthi_ms Avatar asked Aug 04 '10 06:08

karthi_ms


People also ask

Which is reference type?

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.

What is an example of a reference type?

Examples of reference types include: strings, arrays, objects of classes, etc.

What is a reference type variable?

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.

What is the reference type in C#?

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.


1 Answers

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.

like image 179
pmod Avatar answered Oct 05 '22 06:10

pmod