Perl: the Markov chain saw | |
PerlMonks |
Re: arrays and lists, hmmmby Athanasius (Archbishop) |
on Apr 26, 2016 at 03:29 UTC ( [id://1161510]=note: print w/replies, xml ) | Need Help?? |
Hello morgon, I would have expected $y also to be 2, but instead the last element of the list is used instead... But there is no list. I think what’s confusing here is that parentheses are used in Perl to make lists. But that only works in list context. In scalar context, as here, parentheses are only for grouping,1 which in this case makes no difference:
From perldata#List-value-constructors: List values are denoted by separating individual values by commas (and enclosing the list in parentheses where precedence requires it): Update: 1Actually, parentheses are only used for grouping (precedence), regardless of context, as indicated in the perldata quote. My statement that parentheses are used to make lists is a little misleading: they are generally needed, but only because the assignment operator has higher precedence than the comma operator:
Hope that helps,
In Section
Seekers of Perl Wisdom
|
|