in reply to Test for the last element in a foreach

No need for a test on each iteration:
my @children = $category->children; my $last_child = pop @children; foreach $child (@children) { handle_not_last_child($child); } handle_last_child($last_child);

Replies are listed 'Best First'.
Re^2: Test for the last element in a foreach
by smithers (Friar) on Aug 03, 2007 at 19:02 UTC
    Nice mvc++, I like your solution.