On Wed, Feb 19, 2003 at 12:00:33AM -0500, Stephen McCamant wrote: > >>>>> "DP" == Deborah Ariel Pickett <[EMAIL PROTECTED]> > writes: > > DP> One thing that the C comma operator promises is that its left > DP> operand (and all side effects) is completely evaluated before work > DP> starts on the right operand. (This may not be strictly true in > DP> the Perl interpretation of the operator; can a Perl5 developer > DP> comment?) > > It's a matter of some controversy exactly what "promises" with regards > to order of operation Perl5 provides. Unlike C, there's no separate > standard describing what Perl should do: just an implementation, and > some documentation. > > As a matter of implementation, I believe both scalar and list comma > operators have always evaluated their arguments from left to right. > (This also applies to the comma separating sub arguments, if you count > that separately from list comma). > > As for documentation, both the POD and the Camel book use language > that strongly suggests left-to-right evaluation for the scalar comma > ("it evaluates its left argument, throws that value away, then > evaluates its right argument and returns that value") as well as > referring to it as "just like" the C comma. By contrast, they don't > say anything directly about the evaluation order of the list comma. > > On the other hand, there is the following example from perldata (I > can't find it in the Camel, but I can't grep the Camel): > > # A "reverse comma operator". > return (pop(@foo),pop(@foo))[0]; > > which only makes sense if list comma is guaranteed to evaluate left to > right.
Yes, I've never found anything explicitly defining the order of evaluation of the comma operator in list context, but as you suggest there are examples from the perl documentation, the core, its tests and, of course, CPAN which all make use of the left to right ordering. For example, select((select(OUTPUT_HANDLE), $| = 1)[0]); which is (was?) a fairly common idiom, is documented, used in core modules and tested. I suspect that a lot would break if the order of evaluation changed. And I think it would be sensible for Perl 6 to define such an order. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net