Assigning anonymous hash to a list

Abigail abigail at
Wed Jul 31 08:09:49 BST 2013

On Tue, Jul 30, 2013 at 11:36:12PM -0300, Hernan Lopes wrote:
> sorry i meant 1 thing on the left and one thing on the right. Both are
> lists and should be the same size.

Since when? Both:

    my ($a, $b) = (1);


    my ($a, $b) = (1, 2, 3);

are fine.

> On 7/30/13, Hernan Lopes <hernanlopes at> wrote:
> > When you do that, you are implicitly saying:
> >
> > The thing on the left is equals the thing in the right.
> > So, in the left you have 1 thing ( a list because of parenthesis ),
> > and on the right, you have 2 things: string+object.
> >
> > Add parenthesis on the right and transform it into a list.

As said before, adding parenthesis to the RHS of the assignment doesn't
turn that into a list. The RHS is already a list, due to the fact it's
in list context, which in turn is caused by the list of the LHS.

Adding parenthesis to the RHS tells Perl to parse things differently:
the comma is not the top level operator, but a lower level operator.
In fact, the parenthesis on the RHS aren't any more magical than the
parenthesis here:

    3 * (4 + 5);

which is parsed differently compared to:

    3 * 4 + 5;


More information about the mailing list