Is it possible to assign the reference of an array as the value in the key : value pair of a hash table in perl?
Is it possible to assign the reference of an array as the value in
Share
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.
Yes it is. Create a reference to the array by using backslash:
Note that this will link to the actual array, so if you perform a change such as:
That will also mean that
$hash{key}[0]is set to"foo".If that is not what you want, you may copy the values by using an anonymous array reference
[ ... ]:Moreover, you don’t have to go through the array in order to do this. You can simply assign directly:
Read more about making references in perldoc perlref