Perl Monk, Perl Meditation | |
PerlMonks |
Test for the last element in a foreachby tdevil76 (Beadle) |
on Aug 02, 2007 at 20:01 UTC ( [id://630377]=perlquestion: print w/replies, xml ) | Need Help?? |
tdevil76 has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks, What is the cleanest(i.e. short and sweet) way to know if you are working on the last element of the array in a foreach? Thanks!
UPDATE: Sorry - I should be more specific - It isn't an array per se, but a function that is returning an array, i.e.: foreach $subcat ($category->children) { # is this the last element? }
Back to
Seekers of Perl Wisdom
|
|