Say I have this:
my %hash;
$hash{"a"} = "abc";
$hash{"b"} = [1, 2, 3];
How can I, later on, find out if what was stored was a scalar, like in "abc", or an array, like in [1, 2, 3]?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First of all, your example of an array reference is wrong – your
$hash{"b"}will end up with a scalar value: the last element of the list you provided (‘c’ in this case).That said, if you actually do want to see if you have a scalar or a reference, use the
reffunction:Docs