Why do Perl variables need to start with different characters (sigils)?
-
Scalar variables start with
$ -
Hashes start with
% -
Arrays start with
@
Why are they like this?
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.
When I started out using Perl it was explained to me that these characters were chosen because:
$looked a bit like an ‘s’ so that was for scalars,@has an ‘a’ in the middle so that was for arrays, and%was for hashes because it looked like a key-value pair divided by a slash.