On Tue, May 07, 2002 at 03:15:48PM +0100, Graham Barr wrote: > > LAST Executes on implicit loop exit or call to last() > Loop variables may be unknown
Not exactly "unknown". It's just that, in a few cases, their values may have changed by the time the LAST block is executed. > And I think this thread is proposing > > FIRST A PRE block that is executed only on the first itteration > of the loop > > BETWEEN A PRE block that does not execute for the first iteration > of the loop. > > So FIRST and BETWEEN are just shorthand for > > my $count; > loop { > PRE { > if ($count++) { > # BETWEEN code here > } > else { > # FIRST code here > } > } > } Almost. What people are pushing for is more like: BETWEEN A NEXT block that does not execute for the last iteration of the loop. my $count; loop { PRE { unless ($count++) { # FIRST code here } } NEXT { if (<the loop will execute again>) { # BETWEEN code here } } This may seem like a trivial difference at first glance, but it's a matter of scope. The latter interpretation means that code such as: for 1..3 -> $thing { print $thing _ ", "; BETWEEN { print $thing _ "\n"; } } Will output: 1, 1 2, 2 3, Not: 1, 2 2, 3 3, Which seems intuitively right. It's only with variables lexically scoped outside the loop and that change values in the condition itself that we encounter Damian's conundrum. Allison