type of reference

M

Michael Goerz

Hi,

is there a way to find out the type of the datastructure a reference is
pointing to? Suppose I have an array of references and basic types like
this:

@testarray = (
["bla", "xyz"],
{"key" => "value"},
\$var,
"blabla",
123 );

Could I write some function 'typeOfElem', so that
typeOfElem($testarray[0]); prints "reference to array",
typeOfElem($testarray[1]); prints "reference to hash"
typeOfElem($testarray[2]); prints "reference to scalar"
typeOfElem($testarray[3]); prints "scalar"
typeOfElem($testarray[4]); prints "scalar"

Thanks,
Michael Goerz
 
A

A. Sinan Unur

is there a way to find out the type of the datastructure a reference
is pointing to? Suppose I have an array of references and basic types
like this:
....

Could I write some function 'typeOfElem', so that
typeOfElem($testarray[0]); prints "reference to array",
typeOfElem($testarray[1]); prints "reference to hash"
typeOfElem($testarray[2]); prints "reference to scalar"
typeOfElem($testarray[3]); prints "scalar"
typeOfElem($testarray[4]); prints "scalar"

Congratulations! You have asked a SAQ (self answering question):

perldoc -f ref

http://www.ginini.com/perlsaq.html

You should make yourself familiar with the builtins provided by Perl:

perldoc perlfunc

Have you read the posting guidelines for this group?

Sinan

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
 
M

Michael Goerz

A. Sinan Unur said:
Congratulations! You have asked a SAQ (self answering question):

perldoc -f ref

http://www.ginini.com/perlsaq.html

You should make yourself familiar with the builtins provided by Perl:

perldoc perlfunc

Have you read the posting guidelines for this group?

Sinan
Thanks,... and sorry. I just missed that one somehow.

Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top