in reply to Re^2: use of parentheses around a variable
in thread use of parentheses around a variable
-
(my $var) is a list with one scalar called $var, and introduces $var to the current scope context.
-
my ($v1, $v2) is a list with two scalars ($v1, $v2) and introduces both to the current scope context.
-
(my $v1, $v2) is a list with two scalars, but only introduces $v1 to the current scope context, meaning that if use strict is in effect, $v2 should be already introduced in the context or an error will occur.
-
When there is a list on the left-hand-side of an assignment, it forces list context to the right-hand-side (IOW, the right-hand-side will be interpreted as a list), so, my ($v) = @_ reads the first element of @_ and put it in $v.
-
When there is a scalar on the left-hand-side of an assignment, it forces scalar context to the right-hand-side (forces it to be interpreted as a scalar, pretty much as if you had put the word scalar in front of it), so, my $v = @_ is the same as my $v = scalar @_ and, because an array in scalar context is the number of its elements, this puts the number of elements of @_ in $v.
Simple, no? :-)