Question: I sometimes see Perl code like this:

```
my ( $variable ) = blah....

```

What is the point of putting parentheses around a single variable? I thought parentheses were only used when declaring multiple variables, like:

```
my ( $var1, $var2, $var3 ) = blah...

```

Answer: 
You are confusing two different things. First off, when using `my` to declare several variables, you need to use parentheses:

```
my $foo, $bar;  

```

Does not work, as it is considered to be two different statements:

```
my $foo;
$bar;

```

So you need parentheses to group together the argument into an argument list to the *function* `my`:

```
my($foo, $bar);

```

Secondly, you have explicit grouping in order to invoke list context:

```
$foo, $bar = "a", "b"; # wrong!

```

Will be considered three separate statements:

```
$foo;
$bar = "a";
"b";

```

But if you use parentheses to group `$foo` and `$bar` into a list, the assignment operator will use a list context:

```
($foo, $bar) = ("a", "b");

```

Curiously, if you remove the RHS parentheses, you will also experience a hickup:

```
($foo, $bar) = "a", "b"; # Useless use of a constant (b) in void context

```

But that is because the `=` operator has higher precedence than comma `,`, which you can see in [perlop](http://perldoc.perl.org/perlop.html). If you try:

```
my @array = ("a", "b");
($foo, $bar) = @array;

```

You will get the desired behaviour without parentheses.

Now to complete the circle, lets remove the list context in the above and see what happens:

```
my @array = ("a", "b");
$foo = @array;
print $foo;

```

This prints `2`, because the array is evaluated in scalar context, and arrays in scalar context return the number of elements they contain. In this case, it is `2`.

Hence, statements such as these use list context:

```
my ($foo) = @array;          # $foo is set to $array[0], first array element
my ($bar) = ("a", "b", "c"); # $bar is set to "a", first list element

```

It is a way of overriding the scalar context which is implied in scalar assignment. For comparison, these assignments are in scalar context:

```
my $foo = @array;            # $foo is set to the number of elements in the array
my $bar = ("a", "b", "c");   # $bar is set to "c", last list element

```
[*This answer is also found in table format [here](https://www.perlmonks.org/?node_id=790129).*]

The symbol `=` is compiled into one of two assignment operators:

* A *list assignment operator* (`aassign`) is used if the left-hand side (LHS) of a `=` is some kind of aggregate.
* A *scalar assignment operator* (`sassign`) is used otherwise.

The following are considered to be aggregates:

* Any expression in parentheses (e.g. `(...)`)
* An array (e.g. `@array`)
* An array slice (e.g. `@array[...]`)
* A hash (e.g. `%hash`)
* A hash slice (e.g. `@hash{...}`)
* Any of the above preceded by `my`, `our` or `local`

There are two differences between the operators.

Context of Operands
-------------------

The two operators differ in the context in which their operands are evaluated.

* The scalar assignment evaluates both of its operands in scalar context.

```
  # @array evaluated in scalar context.
  my $count = @array;

```
* The list assignment evaluates both of its operands in list context.

```
  # @array evaluated in list context.
  my @copy = @array;

```

```
  # @array evaluated in list context.
  my ($first) = @array;

```

Value(s) Returned
-----------------

The two operators differ in what they return.

* The scalar assignment ...

	+ ... in scalar context evaluates to its LHS as an lvalue.

	```
	  # The s/// operates on $copy.
	  (my $copy = $str) =~ s/\\/\\\\/g;

	```
	+ ... in list context evaluates to its LHS as an lvalue.

	```
	  # Prints $x.
	  print($x = $y);

	```
* The list assignment ...

	+ ... in scalar context evaluates to the number of scalars returned by its RHS.

	```
	  # Only dies if f() returns an empty list.
	  # This does not die if f() returns a
	  # false scalar like zero or undef.
	  my ($x) = f() or die;

	```

	```
	  # $counts gets the number of scalars returns by f().
	  my $count = () = f();

	```
	+ ... in list context evaluates to the scalars returned by its LHS as lvalues.

	```
	  # Prints @x.
	  print(@x = @y);

	```