I know @array[0,2,6] is an array with multiple values.
And I was under the belief that $scalar=3 is a single variable with a single scalar value.
However, what is $array[3, 4]? Is it a scalar variable with two values?
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.
@array[0,2,6](or more generically@array[ EXPR ]) is an array slice. (See perldata) The index expression is evaluated in list context, the returned list is taken to be a list of indexes, and the elements identified by those indexes are returned by the slice.$array[ EXPR ]is an array element. The index expression is evaluated in scalar context, the returned value is taken to be an index, and the element identified by that index is returned.The code
3,4evaluates to4in scalar context — See the comma operator in perlop — so$array[3,4]is the same as$array[4]except for a void context warning.