Assigning anonymous hash to a list

Smylers Smylers at
Tue Jul 30 22:17:56 BST 2013

gvim writes:

> On 30/07/2013 20:09, Joseph Werner wrote:
> > It is because you are not assigning a list value to a list.  You are
> > assigning a scalar value that is the result of a ',' expression  to
> > the first element in the list.
> Got it. Nothing to do with the hashref. Should have used parens ...


> ... to create list context.

No -- you already had list context!

But , has lower precedence than = does (see perldoc perlop). So your

  my ($str, $ref) = 'text', {a => 1, b => 2, c => 3};

is parsed as first do this -- which is a list-context assignment:

  my ($str, $ref) = 'text'

and then 'do' this -- which is just some data, in void context:

  {a => 1, b => 2, c => 3}

The extra parens on the right don't change any context; they just
restrict the comma to only operating inside those parens, rather than
splitting up your statement in an unwanted place.

Stop drug companies hiding negative research results.
Sign the AllTrials petition to get all clinical research results published.
Read more:

More information about the mailing list