in reply to Test for the last element in a foreach

I was thinking of:
my @array = (1 .. 10); my $counter; foreach my $element (@array) { print "Last element follows now!\n" if ++$counter == scalar(@ar +ray); print "$element\n"; }

Output:

1 2 3 4 5 6 7 8 9 Last element follows now! 10

You can leave out the scalar function but then you have to take care that the test does not get evaluated in list context.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James