Jul 5, 2000, 7:22 PM
Post #5 of 9
As rGeoffrey mentions, there is a difference between the ( ) and the [ ] . Both are often thought of as "list" operators.
[ ] returns a reference. References are of course simply scalars, so in rGeoffrey's example, the last element of the list is a scalar which also happens to be a pointer to a list. $a itself would be a memory location. When we follow the reference, $a-> would be "three".
( ) though is not a list operator. It simply sets precedence. In Cure's example precedence doesn't matter. The lists are simply combined. So what, then, does ( ) have to do with list context? Why doesn't:
@a = 1,2,3; work as expected without the ( )? It would seem to imply that ( )'s make a "list" but really that is the work of the comma. A comma, in list context is simply a list delimiter. In scalar context, it evaluates the left side, evaluates the right hand side then returns the result from the right. @a = 1,2,3 is really saying (@a = 1), 2, 3. First it does the assignment, throws away the results, eventually returning a "3" if you cared to check its return.
In summary, the ( ) does not make a list. It simply prevents the = from being executed first. The order of operation is irrelevant in Cure's example; the outer ( )'s protect it from the =. The inner ( )s simply make it a combination of lists. It is expanded just as (@a, @b) would be.