http://qs321.pair.com?node_id=11140738


in reply to Perl's feature to determine, in current point of loop, that this is the last one?

...that this is the last of the loop there will be no next iteration ?

As shown in jwkrahn's example, you have to code it in yourself. (And this is usually quite possible.)

But perl itself will not know that it's in the last loop until that last loop has terminated and the looping condition is re-evaluated (and fails).
By that time the moment has passed, and all perl could tell you is "Oh ... that last loop I just did was the final loop".

If you're looking for a way to bail out of a loop before the loop condition has failed, you can always use last:
perl -le 'for(1..10){print $_; last if $_ == 5}' 1 2 3 4 5
Cheers,
Rob