Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Test for the last element in a foreach

by NetWallah (Canon)
on Aug 03, 2007 at 04:23 UTC ( [id://630442]=note: print w/replies, xml ) Need Help??


in reply to Test for the last element in a foreach

This seems the simplest/cleanest to me:
my $LastSubCat; foreach my $subcat ($category->children) { $LastSubCat = $subcat; # Code to use $subcat } # $LastSubCat now contains the value of the last element

     "An undefined problem has an infinite number of solutions." - Robert A. Humphrey         "If you're not part of the solution, you're part of the precipitate." - Henry J. Tillman

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://630442]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2025-03-17 05:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When you first encountered Perl, which feature amazed you the most?










    Results (54 votes). Check out past polls.