Assigning anonymous hash to a list
Uri Guttman
uri at stemsystems.com
Wed Jul 31 01:40:43 BST 2013
On 07/30/2013 06:52 PM, Joseph Werner wrote:
> Hmmm. Yitzchak Scott-Thoennes, I recognize, Abigail I do not (perhaps
> I should?)
>
> So, Yitzchak, is this, in fact, a simple matter of operator precedence
> in that the ',' operator is of lower precedence than the assignment
> operator (absurd though that may seem) AND not a case of a scalar
> value (which is the result of a Perl expression involving a ','
> operator) being offered to a list assignment?
perldoc perlop shows the comma op has very low precedence. it allows for
this:
$foo = 1, $bar = 2 ;
that does what you think it does, 2 assignments. the example in question
breaks into 2 expressions connected by a comma (assignment in perl is
still just an expression). the left expression does the assignment and
the right expression has nowhere to go (hence its void context). as
others (abigail too) have shown, warnings will catch useless data in
void context.
so parens around the right side changes where the comma binds to just
inside the parens. now it assigns that list to the LHS list. note that
the comma is now a list separator and not the scalar comma op.
so this is absolutely a precedence issue and nothing else. the key is
that assignment binds tighter than the comma. your eyes may say
otherwise but perl (and abigail) knows better! :)
thanx,
uri
--
Uri Guttman - The Perl Hunter
The Best Perl Jobs, The Best Perl Hackers
http://PerlHunter.com
More information about the london.pm
mailing list